@@ -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);
0 commit comments