Skip to content

Commit c5c7fc8

Browse files
johnniwintherCommit Queue
authored andcommitted
[cfe] Add introductory to SourceExtensionTypeDeclarationBuilder
Change-Id: I30b7dd3b69e25a2e611d7ae1bb221a823fe092ce Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389461 Reviewed-by: Jens Johansen <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
1 parent 9541425 commit c5c7fc8

File tree

3 files changed

+36
-35
lines changed

3 files changed

+36
-35
lines changed

pkg/front_end/lib/src/source/source_extension_type_declaration_builder.dart

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,12 @@ class SourceExtensionTypeDeclarationBuilder
6161
@override
6262
final Uri fileUri;
6363

64-
// TODO(johnniwinther): Avoid exposing this. Annotations for macros and
65-
// patches should be computing from within the builder.
66-
final List<MetadataBuilder>? metadata;
67-
6864
final Modifiers _modifiers;
6965

7066
@override
7167
final List<ConstructorReferenceBuilder>? constructorReferences;
7268

73-
final ExtensionTypeDeclaration _extensionTypeDeclaration;
69+
late final ExtensionTypeDeclaration _extensionTypeDeclaration;
7470

7571
SourceExtensionTypeDeclarationBuilder? _origin;
7672

@@ -93,6 +89,8 @@ class SourceExtensionTypeDeclarationBuilder
9389
@override
9490
List<TypeBuilder>? interfaceBuilders;
9591

92+
final ExtensionTypeFragment _introductory;
93+
9694
FieldFragment? _representationFieldFragment;
9795

9896
SourceFieldBuilder? _representationFieldBuilder;
@@ -102,33 +100,43 @@ class SourceExtensionTypeDeclarationBuilder
102100
Nullability? _nullability;
103101

104102
SourceExtensionTypeDeclarationBuilder(
105-
{required this.metadata,
106-
required Modifiers modifiers,
107-
required this.name,
108-
required this.typeParameters,
109-
required this.interfaceBuilders,
110-
required this.typeParameterScope,
111-
required DeclarationNameSpaceBuilder nameSpaceBuilder,
103+
{required this.name,
112104
required SourceLibraryBuilder enclosingLibraryBuilder,
113105
required this.constructorReferences,
114106
required this.fileUri,
115107
required int startOffset,
116108
required int nameOffset,
117109
required int endOffset,
110+
required ExtensionTypeFragment fragment,
118111
required this.indexedContainer,
119112
required FieldFragment? representationFieldFragment})
120113
: parent = enclosingLibraryBuilder,
121114
charOffset = nameOffset,
122-
_modifiers = modifiers,
123-
_extensionTypeDeclaration = new ExtensionTypeDeclaration(
124-
name: name,
125-
fileUri: fileUri,
126-
typeParameters: NominalVariableBuilder.typeParametersFromBuilders(
127-
typeParameters),
128-
reference: indexedContainer?.reference)
129-
..fileOffset = nameOffset,
130-
_nameSpaceBuilder = nameSpaceBuilder,
131-
_representationFieldFragment = representationFieldFragment;
115+
_modifiers = fragment.modifiers,
116+
typeParameters = fragment.typeParameters,
117+
interfaceBuilders = fragment.interfaces,
118+
typeParameterScope = fragment.typeParameterScope,
119+
_introductory = fragment,
120+
_nameSpaceBuilder = fragment.toDeclarationNameSpaceBuilder(),
121+
_representationFieldFragment = representationFieldFragment {
122+
_introductory.builder = this;
123+
_introductory.bodyScope.declarationBuilder = this;
124+
125+
// TODO(johnniwinther): Move this to the [build] once augmentations are
126+
// handled through fragments.
127+
_extensionTypeDeclaration = new ExtensionTypeDeclaration(
128+
name: name,
129+
fileUri: fileUri,
130+
typeParameters: NominalVariableBuilder.typeParametersFromBuilders(
131+
fragment.typeParameters),
132+
reference: indexedContainer?.reference)
133+
..fileOffset = nameOffset;
134+
}
135+
136+
// Coverage-ignore(suite): Not run.
137+
// TODO(johnniwinther): Avoid exposing this. Annotations for macros and
138+
// patches should be computing from within the builder.
139+
List<MetadataBuilder>? get metadata => _introductory.metadata;
132140

133141
@override
134142
LookupScope get scope => _scope;
@@ -725,13 +733,13 @@ class SourceExtensionTypeDeclarationBuilder
725733
List<DelayedDefaultValueCloner> delayedDefaultValueCloners) {
726734
MetadataBuilder.buildAnnotations(
727735
annotatable,
728-
metadata,
736+
_introductory.metadata,
729737
createBodyBuilderContext(
730738
inOutlineBuildingPhase: true,
731739
inMetadata: true,
732740
inConstFields: false),
733741
libraryBuilder,
734-
fileUri,
742+
_introductory.fileUri,
735743
libraryBuilder.scope);
736744

737745
super.buildOutlineExpressions(classHierarchy, delayedDefaultValueCloners);

pkg/front_end/lib/src/source/type_parameter_scope_builder.dart

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,23 +292,16 @@ class _Added {
292292
}
293293
SourceExtensionTypeDeclarationBuilder extensionTypeDeclarationBuilder =
294294
new SourceExtensionTypeDeclarationBuilder(
295-
metadata: fragment.metadata,
296-
modifiers: fragment.modifiers,
297295
name: fragment.name,
298-
typeParameters: fragment.typeParameters,
299-
interfaceBuilders: fragment.interfaces,
300-
typeParameterScope: fragment.typeParameterScope,
301-
nameSpaceBuilder: fragment.toDeclarationNameSpaceBuilder(),
302296
enclosingLibraryBuilder: enclosingLibraryBuilder,
303297
constructorReferences: fragment.constructorReferences,
304298
fileUri: fragment.fileUri,
305299
startOffset: fragment.startOffset,
306300
nameOffset: fragment.nameOffset,
307301
endOffset: fragment.endOffset,
302+
fragment: fragment,
308303
indexedContainer: indexedContainer,
309304
representationFieldFragment: representationFieldFragment);
310-
fragment.builder = extensionTypeDeclarationBuilder;
311-
fragment.bodyScope.declarationBuilder = extensionTypeDeclarationBuilder;
312305
builders.add(new _AddBuilder(
313306
fragment.name,
314307
extensionTypeDeclarationBuilder,

pkg/front_end/test/coverage_suite_expected.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ const Map<String, ({int hitCount, int missCount})> _expect = {
836836
// 100.0%.
837837
"package:front_end/src/source/source_extension_type_declaration_builder.dart":
838838
(
839-
hitCount: 492,
839+
hitCount: 509,
840840
missCount: 0,
841841
),
842842
// 100.0%.
@@ -886,7 +886,7 @@ const Map<String, ({int hitCount, int missCount})> _expect = {
886886
),
887887
// 100.0%.
888888
"package:front_end/src/source/type_parameter_scope_builder.dart": (
889-
hitCount: 684,
889+
hitCount: 675,
890890
missCount: 0,
891891
),
892892
// 100.0%.
@@ -921,7 +921,7 @@ const Map<String, ({int hitCount, int missCount})> _expect = {
921921
),
922922
// 100.0%.
923923
"package:front_end/src/type_inference/inference_visitor.dart": (
924-
hitCount: 8219,
924+
hitCount: 8218,
925925
missCount: 0,
926926
),
927927
// 100.0%.

0 commit comments

Comments
 (0)