diff --git a/goldens/foo/lib/foo.analyzer.json b/goldens/foo/lib/foo.analyzer.json index 3a26f5cb..6366d2f3 100644 --- a/goldens/foo/lib/foo.analyzer.json +++ b/goldens/foo/lib/foo.analyzer.json @@ -197,6 +197,9 @@ ], "namedParameters": [] } + }, + "properties": { + "isClass": true } }, "Bar": { @@ -234,6 +237,9 @@ } } } + }, + "properties": { + "isClass": true } } } diff --git a/goldens/foo/lib/foo.cfe.json b/goldens/foo/lib/foo.cfe.json index b718b2bc..19f1148d 100644 --- a/goldens/foo/lib/foo.cfe.json +++ b/goldens/foo/lib/foo.cfe.json @@ -13,6 +13,9 @@ "isStatic": false } } + }, + "properties": { + "isClass": true } }, "Bar": { @@ -26,6 +29,9 @@ "isStatic": false } } + }, + "properties": { + "isClass": true } } } diff --git a/pkgs/_analyzer_macros/lib/query_service.dart b/pkgs/_analyzer_macros/lib/query_service.dart index 66af2894..b78ae3ad 100644 --- a/pkgs/_analyzer_macros/lib/query_service.dart +++ b/pkgs/_analyzer_macros/lib/query_service.dart @@ -35,7 +35,7 @@ class AnalyzerQueryService implements QueryService { final types = AnalyzerTypeHierarchy(library.typeProvider) ..addInterfaceElement(clazz); - final interface = Interface(); + final interface = Interface(properties: Properties(isClass: true)); for (final constructor in clazz.constructors) { interface.members[constructor.name] = Member( requiredPositionalParameters: constructor diff --git a/pkgs/_cfe_macros/lib/query_service.dart b/pkgs/_cfe_macros/lib/query_service.dart index 6686830c..064041f1 100644 --- a/pkgs/_cfe_macros/lib/query_service.dart +++ b/pkgs/_cfe_macros/lib/query_service.dart @@ -45,7 +45,7 @@ class CfeQueryService implements QueryService { if (classBuilder == null) throw StateError('Not found $target'); final fieldIterator = classBuilder.fullMemberIterator(); - final interface = Interface(); + final interface = Interface(properties: Properties(isClass: true)); while (fieldIterator.moveNext()) { final current = fieldIterator.current; interface.members[current.name] = Member( diff --git a/pkgs/_macro_client/lib/macro_client.dart b/pkgs/_macro_client/lib/macro_client.dart index d54b9f6c..39ecb573 100644 --- a/pkgs/_macro_client/lib/macro_client.dart +++ b/pkgs/_macro_client/lib/macro_client.dart @@ -9,6 +9,8 @@ import 'package:dart_model/dart_model.dart'; import 'package:macro/macro.dart'; import 'package:macro_service/macro_service.dart'; +import 'src/execute_macro.dart'; + /// Local macro client which runs macros as directed by requests from a remote /// macro host. /// @@ -109,9 +111,27 @@ class MacroClient { error: 'No macro for annotation: ' '${hostRequest.macroAnnotation.asString}'))); } else { - await Scope.macro.runAsync(() async => _sendResponse( - Response.augmentResponse( - await macro.augment(_host, hostRequest.asAugmentRequest), + final augmentRequest = hostRequest.asAugmentRequest; + await Scope.macro + .runAsync(() async => _sendResponse(Response.augmentResponse( + switch (augmentRequest.phase) { + 1 => macro.description.runsInPhases.contains(1) + ? await executeTypesMacro( + macro, _host, augmentRequest) + : null, + 2 => macro.description.runsInPhases.contains(2) + ? await executeDeclarationsMacro( + macro, _host, augmentRequest) + : null, + 3 => macro.description.runsInPhases.contains(3) + ? await executeDefinitionsMacro( + macro, _host, augmentRequest) + : null, + _ => throw StateError( + 'Unexpected phase ${augmentRequest.phase}, ' + 'expected 1, 2, or 3.') + } ?? + AugmentResponse(augmentations: []), requestId: hostRequest.id))); } default: diff --git a/pkgs/_macro_client/lib/src/execute_macro.dart b/pkgs/_macro_client/lib/src/execute_macro.dart new file mode 100644 index 00000000..46cff3c8 --- /dev/null +++ b/pkgs/_macro_client/lib/src/execute_macro.dart @@ -0,0 +1,100 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +import 'dart:async'; + +import 'package:dart_model/dart_model.dart'; +import 'package:macro/macro.dart'; +import 'package:macro_service/macro_service.dart'; + +/// Runs [macro] in the types phase and returns an [AugmentResponse]. +Future executeTypesMacro( + Macro macro, Host host, AugmentRequest request) async { + final target = request.target; + // TODO: https://github.com/dart-lang/macros/issues/100. + final queryResult = await host.query(Query(target: target)); + final properties = + queryResult.uris[target.uri]!.scopes[target.name]!.properties; + switch ((properties, macro)) { + case (Properties(isClass: true), ClassTypesMacro macro): + return await macro.buildTypesForClass(host, request); + case (_, LibraryTypesMacro()): + case (_, ConstructorTypesMacro()): + case (_, MethodTypesMacro()): + case (_, FunctionTypesMacro()): + case (_, FieldTypesMacro()): + case (_, VariableTypesMacro()): + case (_, EnumTypesMacro()): + case (_, ExtensionTypesMacro()): + case (_, ExtensionTypeTypesMacro()): + case (_, MixinTypesMacro()): + case (_, EnumValueTypesMacro()): + case (_, TypeAliasTypesMacro()): + throw UnimplementedError('Unimplemented macro target'); + default: + throw UnsupportedError('Unsupported macro type or invalid target:\n' + 'macro: $macro\ntarget: $target'); + } +} + +/// Runs [macro] in the declarations phase and returns an [AugmentResponse]. +Future executeDeclarationsMacro( + Macro macro, Host host, AugmentRequest request) async { + final target = request.target; + // TODO: https://github.com/dart-lang/macros/issues/100. + final queryResult = await host.query(Query(target: target)); + final properties = + queryResult.uris[target.uri]!.scopes[target.name]!.properties; + + switch ((properties, macro)) { + case (Properties(isClass: true), ClassDeclarationsMacro macro): + return await macro.buildDeclarationsForClass(host, request); + case (_, LibraryDeclarationsMacro()): + case (_, EnumDeclarationsMacro()): + case (_, ExtensionDeclarationsMacro()): + case (_, ExtensionTypeDeclarationsMacro()): + case (_, MixinDeclarationsMacro()): + case (_, EnumValueDeclarationsMacro()): + case (_, ConstructorDeclarationsMacro()): + case (_, MethodDeclarationsMacro()): + case (_, FieldDeclarationsMacro()): + case (_, FunctionDeclarationsMacro()): + case (_, VariableDeclarationsMacro()): + case (_, TypeAliasDeclarationsMacro()): + throw UnimplementedError('Unimplemented macro target'); + default: + throw UnsupportedError('Unsupported macro type or invalid target:\n' + 'macro: $macro\ntarget: $target'); + } +} + +/// Runs [macro] in the definitions phase and returns an [AugmentResponse]. +Future executeDefinitionsMacro( + Macro macro, Host host, AugmentRequest request) async { + final target = request.target; + // TODO: https://github.com/dart-lang/macros/issues/100. + final queryResult = await host.query(Query(target: target)); + final properties = + queryResult.uris[target.uri]!.scopes[target.name]!.properties; + + switch ((properties, macro)) { + case (Properties(isClass: true), ClassDefinitionsMacro macro): + return await macro.buildDefinitionsForClass(host, request); + case (_, LibraryDefinitionsMacro()): + case (_, EnumDefinitionsMacro()): + case (_, ExtensionDefinitionsMacro()): + case (_, ExtensionTypeDefinitionsMacro()): + case (_, MixinDefinitionsMacro()): + case (_, EnumValueDefinitionsMacro()): + case (_, ConstructorDefinitionsMacro()): + case (_, MethodDefinitionsMacro()): + case (_, FieldDefinitionsMacro()): + case (_, FunctionDefinitionsMacro()): + case (_, VariableDefinitionsMacro()): + throw UnimplementedError('Unimplemented macro target'); + default: + throw UnsupportedError('Unsupported macro type or invalid target:\n' + 'macro: $macro\ntarget: $target'); + } +} diff --git a/pkgs/_macro_client/test/macro_client_test.dart b/pkgs/_macro_client/test/macro_client_test.dart index f27494e3..54fde700 100644 --- a/pkgs/_macro_client/test/macro_client_test.dart +++ b/pkgs/_macro_client/test/macro_client_test.dart @@ -14,6 +14,8 @@ import 'package:macro_service/macro_service.dart'; import 'package:test/test.dart'; void main() { + final target = QualifiedName.parse('package:a/a.dart#A'); + for (final protocol in [ Protocol(encoding: ProtocolEncoding.json, version: ProtocolVersion.macros1), Protocol( @@ -40,6 +42,29 @@ void main() { return result; } + void answerTargetQuery(MacroRequest targetQuery, Socket socket) { + expect( + targetQuery, + { + 'id': targetQuery.id, + 'type': 'QueryRequest', + 'value': { + 'query': {'target': target} + }, + }, + ); + Scope.query.run(() => protocol.send( + socket.add, + Response.queryResponse( + QueryResponse( + model: Model() + ..uris[target.uri] = (Library() + ..scopes[target.name] = Interface( + properties: (Properties(isClass: true))))), + requestId: targetQuery.id) + .node)); + } + test('connects to service', () async { final serverSocket = await ServerSocket.bind('localhost', 0); addTearDown(serverSocket.close); @@ -87,7 +112,7 @@ void main() { }); }); - test('sends augmentation requests to macros, sends reponse', () async { + test('sends augmentation requests to macros, sends response', () async { final serverSocket = await ServerSocket.bind('localhost', 0); unawaited(MacroClient.run( @@ -120,8 +145,10 @@ void main() { macroAnnotation: QualifiedName( uri: 'package:_test_macros/declare_x_macro.dart', name: 'DeclareX'), - AugmentRequest(phase: 2)) + AugmentRequest(phase: 2, target: target)) .node); + answerTargetQuery(MacroRequest.fromJson(await responses.next), socket); + final augmentResponse = await responses.next; expect(augmentResponse, { 'requestId': requestId, @@ -174,11 +201,10 @@ void main() { macroAnnotation: QualifiedName( uri: 'package:_test_macros/query_class.dart', name: 'QueryClass'), - AugmentRequest( - phase: 3, - target: - QualifiedName(uri: 'package:foo/foo.dart', name: 'Foo')), + AugmentRequest(phase: 3, target: target), ).node); + answerTargetQuery(MacroRequest.fromJson(await responses.next), socket); + final queryRequest = await responses.next; final queryRequestId = MacroRequest.fromJson(queryRequest).id; expect( @@ -187,9 +213,7 @@ void main() { 'id': queryRequestId, 'type': 'QueryRequest', 'value': { - 'query': { - 'target': {'uri': 'package:foo/foo.dart', 'name': 'Foo'} - } + 'query': {'target': target} }, }, ); @@ -197,9 +221,7 @@ void main() { Scope.query.run(() => protocol.send( socket.add, Response.queryResponse( - QueryResponse( - model: Model() - ..uris['package:foo/foo.dart'] = Library()), + QueryResponse(model: Model()..uris[target.uri] = Library()), requestId: queryRequestId) .node)); @@ -215,8 +237,7 @@ void main() { 'code': [ { 'type': 'String', - 'value': - '// {"uris":{"package:foo/foo.dart":{"scopes":{}}}}' + 'value': '// {"uris":{"${target.uri}":{"scopes":{}}}}' } ] } @@ -249,11 +270,10 @@ void main() { macroAnnotation: QualifiedName( uri: 'package:_test_macros/query_class.dart', name: 'QueryClass'), - AugmentRequest( - phase: 3, - target: QualifiedName( - uri: 'package:foo/foo.dart', name: 'Foo')), + AugmentRequest(phase: 3, target: target), ).node); + unawaited(responses.next.then((response) => + answerTargetQuery(MacroRequest.fromJson(response), socket))); } final queryRequest1 = await responses.next; diff --git a/pkgs/_macro_host/test/macro_host_test.dart b/pkgs/_macro_host/test/macro_host_test.dart index ef5424a4..c8c1da83 100644 --- a/pkgs/_macro_host/test/macro_host_test.dart +++ b/pkgs/_macro_host/test/macro_host_test.dart @@ -33,7 +33,12 @@ void main() { await host.queryMacroPhases(packageConfig, macroAnnotation), {2}); expect( - await host.augment(macroAnnotation, AugmentRequest(phase: 2)), + await host.augment( + macroAnnotation, + AugmentRequest( + phase: 2, + target: QualifiedName( + name: 'Foo', uri: 'package:foo/foo.dart'))), Scope.macro.run(() => AugmentResponse(augmentations: [ Augmentation(code: [Code.string('int get x => 3;')]) ]))); @@ -65,7 +70,8 @@ void main() { Scope.macro.run(() => AugmentResponse(augmentations: [ Augmentation(code: [ Code.string( - '// {"uris":{"package:foo/foo.dart":{"scopes":{}}}}') + '// {"uris":{"package:foo/foo.dart":{"scopes":{"Foo":{' + '"members":{},"properties":{"isClass":true}}}}}}') ]) ]))); }); @@ -102,6 +108,9 @@ class TestQueryService implements QueryService { @override Future handle(QueryRequest request) async { return QueryResponse( - model: Model()..uris['package:foo/foo.dart'] = Library()); + model: Model() + ..uris[request.query.target.uri] = (Library() + ..scopes[request.query.target.name] = + Interface(properties: Properties(isClass: true)))); } } diff --git a/pkgs/_test_macros/lib/declare_x_macro.dart b/pkgs/_test_macros/lib/declare_x_macro.dart index ece158b3..c51d0573 100644 --- a/pkgs/_test_macros/lib/declare_x_macro.dart +++ b/pkgs/_test_macros/lib/declare_x_macro.dart @@ -13,7 +13,7 @@ class DeclareX { const DeclareX(); } -class DeclareXImplementation implements Macro { +class DeclareXImplementation implements ClassDeclarationsMacro { // TODO(davidmorgan): this should be injected by the bootstrap script. @override MacroDescription get description => MacroDescription( @@ -22,7 +22,8 @@ class DeclareXImplementation implements Macro { runsInPhases: [2]); @override - Future augment(Host host, AugmentRequest request) async { + Future buildDeclarationsForClass( + Host host, AugmentRequest request) async { // TODO(davidmorgan): make the host only run in the phases requested so // that this is not needed. if (request.phase != 2) return AugmentResponse(augmentations: []); diff --git a/pkgs/_test_macros/lib/json_codable.dart b/pkgs/_test_macros/lib/json_codable.dart index 3cffb313..bfb4adad 100644 --- a/pkgs/_test_macros/lib/json_codable.dart +++ b/pkgs/_test_macros/lib/json_codable.dart @@ -18,7 +18,8 @@ final _jsonMapTypeForLiteral = '<{{dart:core#String}}, {{dart:core#Object}}?>'; final _jsonMapType = '{{dart:core#Map}}$_jsonMapTypeForLiteral'; final _mapEntryType = '{{dart:core#MapEntry}}'; -class JsonCodableImplementation implements Macro { +class JsonCodableImplementation + implements ClassDeclarationsMacro, ClassDefinitionsMacro { @override MacroDescription get description => MacroDescription( annotation: QualifiedName( @@ -26,15 +27,8 @@ class JsonCodableImplementation implements Macro { runsInPhases: [2, 3]); @override - Future augment(Host host, AugmentRequest request) async { - return switch (request.phase) { - 2 => phase2(host, request), - 3 => phase3(host, request), - _ => AugmentResponse(augmentations: []), - }; - } - - Future phase2(Host host, AugmentRequest request) async { + Future buildDeclarationsForClass( + Host host, AugmentRequest request) async { final target = request.target; return AugmentResponse(augmentations: [ Augmentation(code: expandTemplate(''' @@ -45,7 +39,9 @@ class JsonCodableImplementation implements Macro { ]); } - Future phase3(Host host, AugmentRequest request) async { + @override + Future buildDefinitionsForClass( + Host host, AugmentRequest request) async { final target = request.target; final model = await host.query(Query(target: target)); final clazz = model.uris[target.uri]!.scopes[target.name]!; diff --git a/pkgs/_test_macros/lib/query_class.dart b/pkgs/_test_macros/lib/query_class.dart index 6f652b2a..a34c7acf 100644 --- a/pkgs/_test_macros/lib/query_class.dart +++ b/pkgs/_test_macros/lib/query_class.dart @@ -16,7 +16,7 @@ class QueryClass { const QueryClass(); } -class QueryClassImplementation implements Macro { +class QueryClassImplementation implements ClassDefinitionsMacro { // TODO(davidmorgan): this should be injected by the bootstrap script. @override MacroDescription get description => MacroDescription( @@ -25,11 +25,8 @@ class QueryClassImplementation implements Macro { runsInPhases: [3]); @override - Future augment(Host host, AugmentRequest request) async { - // TODO(davidmorgan): make the host only run in the phases requested so - // that this is not needed. - if (request.phase != 3) return AugmentResponse(augmentations: []); - + Future buildDefinitionsForClass( + Host host, AugmentRequest request) async { final model = await host.query(Query( target: request.target, )); diff --git a/pkgs/macro/lib/macro.dart b/pkgs/macro/lib/macro.dart index f4bcfbc6..40376967 100644 --- a/pkgs/macro/lib/macro.dart +++ b/pkgs/macro/lib/macro.dart @@ -2,11 +2,18 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +import 'dart:async'; + import 'package:dart_model/dart_model.dart'; import 'package:macro_service/macro_service.dart'; -/// A macro: transforms Dart code into Dart code augmentations to apply to the -/// code. +/// The macro host. +abstract interface class Host { + Future query(Query query); + // TODO(davidmorgan): introspection methods go here. +} + +/// The marker interface for all types of macros. abstract interface class Macro { /// Description of the macro. /// @@ -15,15 +22,278 @@ abstract interface class Macro { /// than relying on the user-written macro code to return it. /// MacroDescription get description; +} - /// Generate augmentatations and diagnostics for [request]. - /// - /// The code can be introspected by sending queries to [host]. - Future augment(Host host, AugmentRequest request); +/// The interface for [Macro]s that can be applied to a library directive, and +/// want to contribute new type declarations to the library. +abstract interface class LibraryTypesMacro implements Macro { + FutureOr buildTypesForLibrary( + Host host, AugmentRequest request); } -/// The macro host. -abstract interface class Host { - Future query(Query query); - // TODO(davidmorgan): introspection methods go here. +/// The interface for [Macro]s that can be applied to a library directive, and +/// want to contribute new non-type declarations to the library. +abstract interface class LibraryDeclarationsMacro implements Macro { + FutureOr buildDeclarationsForLibrary( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to a library directive, and +/// want to provide definitions for declarations in the library. +abstract interface class LibraryDefinitionsMacro implements Macro { + FutureOr buildDefinitionsForLibrary( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any top level function, +/// instance method, or static method, and want to contribute new type +/// declarations to the program. +abstract interface class FunctionTypesMacro implements Macro { + FutureOr buildTypesForFunction( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any top level function, +/// instance method, or static method, and want to contribute new non-type +/// declarations to the program. +abstract interface class FunctionDeclarationsMacro implements Macro { + FutureOr buildDeclarationsForFunction( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any top level function, +/// instance method, or static method, and want to augment the function +/// definition. +abstract interface class FunctionDefinitionsMacro implements Macro { + FutureOr buildDefinitionsForFunction( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any top level variable or +/// instance field, and want to contribute new type declarations to the +/// program. +abstract interface class VariableTypesMacro implements Macro { + FutureOr buildTypesForVariable( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any top level variable or +/// instance field and want to contribute new non-type declarations to the +/// program. +abstract interface class VariableDeclarationsMacro implements Macro { + FutureOr buildDeclarationsForVariable( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any top level variable +/// or instance field, and want to augment the variable definition. +abstract interface class VariableDefinitionsMacro implements Macro { + FutureOr buildDefinitionsForVariable( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any class, and want to +/// contribute new type declarations to the program. +abstract interface class ClassTypesMacro implements Macro { + FutureOr buildTypesForClass( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any class, and want to +/// contribute new non-type declarations to the program. +abstract interface class ClassDeclarationsMacro implements Macro { + FutureOr buildDeclarationsForClass( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any class, and want to +/// augment the definitions of the members of that class. +abstract interface class ClassDefinitionsMacro implements Macro { + FutureOr buildDefinitionsForClass( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any enum, and want to +/// contribute new type declarations to the program. +abstract interface class EnumTypesMacro implements Macro { + FutureOr buildTypesForEnum( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any enum, and want to +/// contribute new non-type declarations to the program. +abstract interface class EnumDeclarationsMacro implements Macro { + FutureOr buildDeclarationsForEnum( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any enum, and want to +/// augment the definitions of members or values of that enum. +abstract interface class EnumDefinitionsMacro implements Macro { + FutureOr buildDefinitionsForEnum( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any enum, and want to +/// contribute new type declarations to the program. +abstract interface class EnumValueTypesMacro implements Macro { + FutureOr buildTypesForEnumValue( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any enum, and want to +/// contribute new non-type declarations to the program. +abstract interface class EnumValueDeclarationsMacro implements Macro { + FutureOr buildDeclarationsForEnumValue( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any enum, and want to +/// augment the definitions of members or values of that enum. +abstract interface class EnumValueDefinitionsMacro implements Macro { + FutureOr buildDefinitionsForEnumValue( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any field, and want to +/// contribute new type declarations to the program. +abstract interface class FieldTypesMacro implements Macro { + FutureOr buildTypesForField( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any field, and want to +/// contribute new type declarations to the program. +abstract interface class FieldDeclarationsMacro implements Macro { + FutureOr buildDeclarationsForField( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any field, and want to +/// augment the field definition. +abstract interface class FieldDefinitionsMacro implements Macro { + FutureOr buildDefinitionsForField( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any method, and want to +/// contribute new type declarations to the program. +abstract interface class MethodTypesMacro implements Macro { + FutureOr buildTypesForMethod( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any method, and want to +/// contribute new non-type declarations to the program. +abstract interface class MethodDeclarationsMacro implements Macro { + FutureOr buildDeclarationsForMethod( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any method, and want to +/// augment the function definition. +abstract interface class MethodDefinitionsMacro implements Macro { + FutureOr buildDefinitionsForMethod( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any constructor, and want +/// to contribute new type declarations to the program. +abstract interface class ConstructorTypesMacro implements Macro { + FutureOr buildTypesForConstructor( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any constructors, and +/// want to contribute new non-type declarations to the program. +abstract interface class ConstructorDeclarationsMacro implements Macro { + FutureOr buildDeclarationsForConstructor( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any constructor, and want +/// to augment the function definition. +abstract interface class ConstructorDefinitionsMacro implements Macro { + FutureOr buildDefinitionsForConstructor( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any mixin declaration, and +/// want to contribute new type declarations to the program. +abstract interface class MixinTypesMacro implements Macro { + FutureOr buildTypesForMixin( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any mixin declaration, and +/// want to contribute new non-type declarations to the program. +abstract interface class MixinDeclarationsMacro implements Macro { + FutureOr buildDeclarationsForMixin( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any mixin declaration, and +/// want to augment the definitions of the members of that mixin. +abstract interface class MixinDefinitionsMacro implements Macro { + FutureOr buildDefinitionsForMixin( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any extension declaration, +/// and want to contribute new type declarations to the program. +abstract interface class ExtensionTypesMacro implements Macro { + FutureOr buildTypesForExtension( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any extension declaration, +/// and want to contribute new non-type declarations to the program. +abstract interface class ExtensionDeclarationsMacro implements Macro { + FutureOr buildDeclarationsForExtension( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any extension declaration, +/// and want to augment the definitions of the members of that extension. +abstract interface class ExtensionDefinitionsMacro implements Macro { + FutureOr buildDefinitionsForExtension( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any extension type +/// declaration, and want to contribute new type declarations to the program. +abstract interface class ExtensionTypeTypesMacro implements Macro { + FutureOr buildTypesForExtensionType( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any extension type +/// declaration, and want to contribute new non-type declarations to the +/// program. +abstract interface class ExtensionTypeDeclarationsMacro implements Macro { + FutureOr buildDeclarationsForExtensionType( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any extension type +/// declaration, and want to augment the definitions of the members of that +/// extension. +abstract interface class ExtensionTypeDefinitionsMacro implements Macro { + FutureOr buildDefinitionsForExtensionType( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any type alias +/// declaration, and want to contribute new type declarations to the program. +abstract interface class TypeAliasTypesMacro implements Macro { + FutureOr buildTypesForTypeAlias( + Host host, AugmentRequest request); +} + +/// The interface for [Macro]s that can be applied to any type alias +/// declaration, and want to contribute new non-type declarations to the +/// program. +abstract interface class TypeAliasDeclarationsMacro implements Macro { + FutureOr buildDeclarationsForTypeAlias( + Host host, AugmentRequest request); }