Skip to content

Commit a868303

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Remove FragmentName, inline as name2 / nameOffset2.
Change-Id: If238cd71867501a39e243261228d137f925db1dd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392741 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 06207a7 commit a868303

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1611
-1789
lines changed

pkg/analysis_server/lib/src/lsp/handlers/code_lens/abstract_code_lens_provider.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ abstract class AbstractCodeLensProvider
3333
/// If for any reason the location cannot be computed, returns `null`.
3434
Location? getLocation(Fragment fragment) {
3535
// We can't produce a location to a name if there isn't one.
36-
var nameOffset = fragment.name2?.nameOffset;
36+
var nameOffset = fragment.nameOffset2;
3737
var nameLength = fragment.element.displayName.length;
3838
if (nameOffset == null) {
3939
return null;

pkg/analysis_server/lib/src/lsp/handlers/code_lens/augmentations.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class AugmentationCodeLensProvider extends AbstractCodeLensProvider {
7272
) {
7373
var command =
7474
getNavigationCommand(clientCapabilities, title, targetFragment);
75-
var nameOffset = thisFragment.name2?.nameOffset;
75+
var nameOffset = thisFragment.nameOffset2;
7676
var nameLength = thisFragment.element.displayName.length;
7777
if (command != null && nameOffset != null) {
7878
var range = toRange(

pkg/analysis_server/lib/src/protocol_server.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ Location? newLocation_fromElement2(engine.Element2? element) {
268268
}
269269
if (element is engine.FragmentedElement) {
270270
var fragment = (element as engine.FragmentedElement).firstFragment;
271-
var offset = fragment.name2?.nameOffset ?? 0;
272-
var length = fragment.name2?.name.length ?? 0;
271+
var offset = fragment.nameOffset2 ?? 0;
272+
var length = fragment.name2?.length ?? 0;
273273
var range = engine.SourceRange(offset, length);
274274
return _locationForArgs2(fragment, range);
275275
} else {

pkg/analysis_server/lib/src/services/correction/dart/add_field_formal_parameters.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class AddFieldFormalParameters extends ResolvedCorrectionProducer {
4343
// Compute uninitialized final fields.
4444
var fields = ErrorVerifier.computeNotInitializedFields2(constructor);
4545
fields.retainWhere((FieldElement2 field) => field.isFinal);
46-
fields.sort((a, b) =>
47-
a.firstFragment.name2!.nameOffset - b.firstFragment.name2!.nameOffset);
46+
fields.sort(
47+
(a, b) => a.firstFragment.nameOffset2! - b.firstFragment.nameOffset2!);
4848

4949
// Specialize for Flutter widgets.
5050
if (superType.isExactlyStatelessWidgetType ||

pkg/analysis_server/lib/src/services/correction/dart/make_variable_not_final.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@ class MakeVariableNotFinal extends ResolvedCorrectionProducer {
4545
return;
4646
}
4747

48-
var declaration = NodeLocator(variable.nameOffset).searchWithin(unit);
48+
var nameOffset = variable.firstFragment.nameOffset2;
49+
if (nameOffset == null) {
50+
return;
51+
}
52+
53+
var declaration = NodeLocator(nameOffset).searchWithin(unit);
4954
var declarationList = declaration?.parent;
5055

5156
if (declaration is VariableDeclaration &&

pkg/analysis_server/lib/src/services/correction/dart/replace_return_type.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class ReplaceReturnType extends ResolvedCorrectionProducer {
105105
var classElement = clazz.declaredFragment!.element;
106106
var overriddenList = InheritanceManager3().getOverridden4(
107107
classElement,
108-
Name.forLibrary(classElement.library2, methodName.name),
108+
Name.forLibrary(classElement.library2, methodName),
109109
);
110110

111111
if (overriddenList != null) {

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

Lines changed: 41 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -307,19 +307,19 @@ abstract class ConstructorFragment implements ExecutableFragment {
307307
InstanceFragment? get enclosingFragment;
308308

309309
@override
310-
ConstructorFragmentName? get name2;
310+
String get name2;
311311

312312
@override
313313
ConstructorFragment? get nextFragment;
314314

315-
@override
316-
ConstructorFragment? get previousFragment;
317-
}
318-
319-
/// The name of a [ConstructorFragment].
320-
abstract class ConstructorFragmentName extends FragmentName {
321315
/// The offset of the `.` before the name.
316+
///
317+
/// It is `null` if the fragment is synthetic, or does not specify an
318+
/// explicit name, even if [name2] is `new` in this case.
322319
int? get periodOffset;
320+
321+
@override
322+
ConstructorFragment? get previousFragment;
323323
}
324324

325325
/// The base class for all of the elements in the element model.
@@ -916,17 +916,43 @@ abstract class Fragment {
916916
/// This will be the fragment itself if it is a library fragment.
917917
LibraryFragment get libraryFragment;
918918

919-
/// The name of this fragment.
919+
/// The name of the fragment.
920920
///
921-
/// Returns `null` if the fragment does not have a name, e.g. an unnamed
922-
/// [ExtensionFragment].
921+
/// Never empty.
922+
///
923+
/// If a fragment, e.g. an [ExtensionFragment], does not have a name,
924+
/// then the name is `null`.
923925
///
924-
/// Returns `null` if the fragment is an unnamed [ConstructorFragment],
925-
/// even if its [ConstructorElement2] has the name `new`.
926+
/// For an unnamed [ConstructorFragment] the name is `new`, but [nameOffset2]
927+
/// is `null`. If there is an explicit `ClassName.new`, the name is also
928+
/// `new`, and [nameOffset2] is not `null`. For a synthetic default unnamed
929+
/// [ConstructorElement2] there is always a synthetic [ConstructorFragment]
930+
/// with the name `new`, and [nameOffset2] is `null`.
926931
///
927-
/// Returns `null` if the fragment declaration node does not have the name
928-
/// specified, and the parser inserted a synthetic identifier.
929-
FragmentName? get name2;
932+
/// If the fragment declaration node does not have the name specified, and
933+
/// the parser inserted a synthetic token, then the name is `null`, and
934+
/// [nameOffset2] is `null`.
935+
///
936+
/// For a synthetic [GetterFragment] or [SetterFragment] the name is the
937+
/// name of the corresponding non-synthetic [PropertyInducingFragment],
938+
/// which is usually not `null`, but could be. And `nameOffset2` is `null`
939+
/// for such synthetic fragments.
940+
///
941+
/// For a [SetterFragment] this is the identifier, without `=` at the end.
942+
String? get name2;
943+
944+
/// The offset of the [name2] of this element.
945+
///
946+
/// If a fragment, e.g. an [ExtensionFragment], does not have a name,
947+
/// then the name offset is `null`.
948+
///
949+
/// If the fragment declaration node does not have the name specified, and
950+
/// the parser inserted a synthetic token, then the name is `null`, and
951+
/// the name offset is `null`.
952+
///
953+
/// For a synthetic fragment, e.g. [ConstructorFragment] the name offset
954+
/// is `null`.
955+
int? get nameOffset2;
930956

931957
/// The next fragment in the augmentation chain.
932958
///
@@ -949,32 +975,6 @@ abstract class FragmentedElement {
949975
Fragment get firstFragment;
950976
}
951977

952-
/// The name of a [Fragment].
953-
abstract class FragmentName {
954-
/// The name of the fragment.
955-
///
956-
/// Never empty.
957-
///
958-
/// If a fragment, e.g. an [ExtensionFragment], does not have a name,
959-
/// then the whole [FragmentName] is `null`.
960-
///
961-
/// Similarly, an unnamed [ConstructorFragment] does not have a name, even
962-
/// if the [ConstructorElement2] has the name `new`.
963-
///
964-
/// If the fragment declaration node does not have the name specified, and
965-
/// the parser inserted a synthetic token, then the whole [FragmentName]
966-
/// is `null`.
967-
///
968-
/// For a [SetterFragment] this is the identifier, without `=` at the end.
969-
String get name;
970-
971-
/// The offset of the end of the name.
972-
int get nameEnd;
973-
974-
/// The offset of the name in the file.
975-
int get nameOffset;
976-
}
977-
978978
/// An element that has a [FunctionType] as its [type].
979979
///
980980
/// This also provides convenient access to the parameters and return type.
@@ -1315,9 +1315,6 @@ abstract class LabelElement2 implements Element2, FragmentedElement {
13151315

13161316
@override
13171317
LibraryElement2 get library2;
1318-
1319-
/// The offset of the name in this element.
1320-
int get nameOffset;
13211318
}
13221319

13231320
/// The portion of a [LabelElement2] contributed by a single declaration.
@@ -1667,9 +1664,6 @@ abstract class LocalVariableElement2
16671664

16681665
/// Whether the variable has an initializer at declaration.
16691666
bool get hasInitializer;
1670-
1671-
/// The offset of the name in this element.
1672-
int get nameOffset;
16731667
}
16741668

16751669
/// The portion of a [LocalVariableElement2] contributed by a single

pkg/analyzer/lib/src/dart/analysis/driver.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ import 'package:meta/meta.dart';
9898
// TODO(scheglov): Clean up the list of implicitly analyzed files.
9999
class AnalysisDriver {
100100
/// The version of data format, should be incremented on every format change.
101-
static const int DATA_VERSION = 410;
101+
static const int DATA_VERSION = 411;
102102

103103
/// The number of exception contexts allowed to write. Once this field is
104104
/// zero, we stop writing any new exception contexts in this process.

0 commit comments

Comments
 (0)