Macro. Include macro annotations into metadata.
The specification was changes:
https://github.com/dart-lang/language/pull/3450
Change-Id: I6ac4e7a90113e10a9d0d87f640456fcf602e5e8f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/334981
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analyzer/lib/src/summary2/macro_application.dart b/pkg/analyzer/lib/src/summary2/macro_application.dart
index fcc2b23..7490fc9 100644
--- a/pkg/analyzer/lib/src/summary2/macro_application.dart
+++ b/pkg/analyzer/lib/src/summary2/macro_application.dart
@@ -256,9 +256,6 @@
continue;
}
- // We don't want to include it into metadata.
- declarationBuilder.macroAnnotations.add(annotation.elementAnnotation!);
-
final arguments = await _runWithCatchingExceptions(
() async {
return _buildArguments(
diff --git a/pkg/analyzer/lib/src/summary2/macro_declarations.dart b/pkg/analyzer/lib/src/summary2/macro_declarations.dart
index cf06969..3ca0a2f 100644
--- a/pkg/analyzer/lib/src/summary2/macro_declarations.dart
+++ b/pkg/analyzer/lib/src/summary2/macro_declarations.dart
@@ -50,9 +50,6 @@
late final DeclarationBuilderFromElement fromElement =
DeclarationBuilderFromElement(this);
- /// The annotations that were recognized as macro applications.
- final Set<ElementAnnotation> macroAnnotations = {};
-
DeclarationBuilder({
required this.nodeOfElement,
});
@@ -68,10 +65,6 @@
macro.MetadataAnnotationImpl? _buildMetadataElement(
ElementAnnotation annotation,
) {
- if (macroAnnotations.contains(annotation)) {
- return null;
- }
-
annotation as ElementAnnotationImpl;
final node = annotation.annotationAst;
diff --git a/pkg/analyzer/test/src/dart/resolution/node_text_expectations.dart b/pkg/analyzer/test/src/dart/resolution/node_text_expectations.dart
index fc52012..4916f2a 100644
--- a/pkg/analyzer/test/src/dart/resolution/node_text_expectations.dart
+++ b/pkg/analyzer/test/src/dart/resolution/node_text_expectations.dart
@@ -14,7 +14,7 @@
import 'package:test_reflective_loader/test_reflective_loader.dart';
class NodeTextExpectationsCollector {
- static const updatingIsEnabled = false;
+ static const updatingIsEnabled = true;
static const assertMethods = [
_AssertMethod(
@@ -43,6 +43,11 @@
argumentIndex: 1,
),
_AssertMethod(
+ className: 'MacroDeclarationsIntrospectTest',
+ methodName: '_assertIntrospectText',
+ argumentIndex: 1,
+ ),
+ _AssertMethod(
className: 'MacroTypesIntrospectTest',
methodName: '_assertIntrospectText',
argumentIndex: 1,
diff --git a/pkg/analyzer/test/src/summary/macro/introspect_declarations_phase.dart b/pkg/analyzer/test/src/summary/macro/introspect_declarations_phase.dart
index 3df98e9..1342c84 100644
--- a/pkg/analyzer/test/src/summary/macro/introspect_declarations_phase.dart
+++ b/pkg/analyzer/test/src/summary/macro/introspect_declarations_phase.dart
@@ -11,9 +11,11 @@
/*macro*/ class IntrospectDeclarationsPhaseMacro
implements ClassDeclarationsMacro, MixinDeclarationsMacro {
final Set<Object?> withDetailsFor;
+ final bool withMetadata;
const IntrospectDeclarationsPhaseMacro({
this.withDetailsFor = const {},
+ this.withMetadata = false,
});
@override
@@ -51,6 +53,7 @@
final printer = _Printer(
sink: sink,
+ withMetadata: withMetadata,
introspector: builder,
withDetailsFor: {
declarationName,
@@ -69,17 +72,15 @@
}
}
-class _Printer with SharedPrinter {
- @override
- final TreeStringSink sink;
-
+class _Printer extends SharedPrinter {
@override
final DeclarationPhaseIntrospector introspector;
final Set<String> withDetailsFor;
_Printer({
- required this.sink,
+ required super.sink,
+ required super.withMetadata,
required this.introspector,
required this.withDetailsFor,
});
diff --git a/pkg/analyzer/test/src/summary/macro/introspect_shared.dart b/pkg/analyzer/test/src/summary/macro/introspect_shared.dart
index 5c50fb1..e52e1bf 100644
--- a/pkg/analyzer/test/src/summary/macro/introspect_shared.dart
+++ b/pkg/analyzer/test/src/summary/macro/introspect_shared.dart
@@ -4,12 +4,18 @@
import 'package:_fe_analyzer_shared/src/macros/api.dart';
-mixin SharedPrinter {
+abstract class SharedPrinter {
+ final TreeStringSink sink;
+ final bool withMetadata;
+
Identifier? _enclosingDeclarationIdentifier;
- TypePhaseIntrospector get introspector;
+ SharedPrinter({
+ required this.sink,
+ required this.withMetadata,
+ });
- TreeStringSink get sink;
+ TypePhaseIntrospector get introspector;
bool shouldWriteDetailsFor(Declaration declaration) {
return true;
@@ -125,11 +131,13 @@
}
Future<void> _writeMetadata(Annotatable e) async {
- await sink.writeElements(
- 'metadata',
- e.metadata,
- _writeMetadataAnnotation,
- );
+ if (withMetadata) {
+ await sink.writeElements(
+ 'metadata',
+ e.metadata,
+ _writeMetadataAnnotation,
+ );
+ }
}
Future<void> _writeMetadataAnnotation(MetadataAnnotation e) async {
diff --git a/pkg/analyzer/test/src/summary/macro/introspect_types_phase.dart b/pkg/analyzer/test/src/summary/macro/introspect_types_phase.dart
index b90afd3..070be96 100644
--- a/pkg/analyzer/test/src/summary/macro/introspect_types_phase.dart
+++ b/pkg/analyzer/test/src/summary/macro/introspect_types_phase.dart
@@ -10,7 +10,11 @@
/*macro*/ class IntrospectTypesPhaseMacro
implements ClassTypesMacro, MethodTypesMacro, MixinTypesMacro {
- const IntrospectTypesPhaseMacro();
+ final bool withMetadata;
+
+ const IntrospectTypesPhaseMacro({
+ this.withMetadata = false,
+ });
@override
Future<void> buildTypesForClass(declaration, builder) async {
@@ -45,6 +49,7 @@
final printer = _Printer(
sink: sink,
+ withMetadata: withMetadata,
introspector: builder,
);
await f(printer);
@@ -59,15 +64,13 @@
}
}
-class _Printer with SharedPrinter {
- @override
- final TreeStringSink sink;
-
+class _Printer extends SharedPrinter {
@override
final TypePhaseIntrospector introspector;
_Printer({
- required this.sink,
+ required super.sink,
+ required super.withMetadata,
required this.introspector,
});
}
diff --git a/pkg/analyzer/test/src/summary/macro_test.dart b/pkg/analyzer/test/src/summary/macro_test.dart
index 2e9b9e2..72a2b6d 100644
--- a/pkg/analyzer/test/src/summary/macro_test.dart
+++ b/pkg/analyzer/test/src/summary/macro_test.dart
@@ -1583,10 +1583,14 @@
@IntrospectDeclarationsPhaseMacro(
withDetailsFor: {'A'},
+ withMetadata: true,
)
class X extends A {}
''', r'''
class X
+ metadata
+ ConstructorMetadataAnnotation
+ type: IntrospectDeclarationsPhaseMacro
superclass: A
class A
superclass: Object
@@ -1618,10 +1622,14 @@
@IntrospectDeclarationsPhaseMacro(
withDetailsFor: {'A'},
+ withMetadata: true,
)
class X extends A {}
''', r'''
class X
+ metadata
+ ConstructorMetadataAnnotation
+ type: IntrospectDeclarationsPhaseMacro
superclass: A
class A
superclass: Object
@@ -1703,10 +1711,14 @@
@IntrospectDeclarationsPhaseMacro(
withDetailsFor: {'A'},
+ withMetadata: true,
)
class X extends A {}
''', r'''
class X
+ metadata
+ ConstructorMetadataAnnotation
+ type: IntrospectDeclarationsPhaseMacro
superclass: A
class A
metadata
@@ -1734,10 +1746,14 @@
@IntrospectDeclarationsPhaseMacro(
withDetailsFor: {'B'},
+ withMetadata: true,
)
class X extends B {}
''', r'''
class X
+ metadata
+ ConstructorMetadataAnnotation
+ type: IntrospectDeclarationsPhaseMacro
superclass: B
class B
metadata
@@ -1768,10 +1784,14 @@
@IntrospectDeclarationsPhaseMacro(
withDetailsFor: {'B'},
+ withMetadata: true,
)
class X extends B {}
''', r'''
class X
+ metadata
+ ConstructorMetadataAnnotation
+ type: IntrospectDeclarationsPhaseMacro
superclass: B
class B
metadata
@@ -1802,10 +1822,14 @@
@IntrospectDeclarationsPhaseMacro(
withDetailsFor: {'B'},
+ withMetadata: true,
)
class X extends B {}
''', r'''
class X
+ metadata
+ ConstructorMetadataAnnotation
+ type: IntrospectDeclarationsPhaseMacro
superclass: B
class B
metadata
@@ -1832,10 +1856,14 @@
@IntrospectDeclarationsPhaseMacro(
withDetailsFor: {'B'},
+ withMetadata: true,
)
class X extends B {}
''', r'''
class X
+ metadata
+ ConstructorMetadataAnnotation
+ type: IntrospectDeclarationsPhaseMacro
superclass: B
class B
metadata
@@ -1865,10 +1893,14 @@
@IntrospectDeclarationsPhaseMacro(
withDetailsFor: {'B'},
+ withMetadata: true,
)
class X extends B {}
''', r'''
class X
+ metadata
+ ConstructorMetadataAnnotation
+ type: IntrospectDeclarationsPhaseMacro
superclass: B
class B
metadata
@@ -1898,10 +1930,14 @@
@IntrospectDeclarationsPhaseMacro(
withDetailsFor: {'B'},
+ withMetadata: true,
)
class X extends B {}
''', r'''
class X
+ metadata
+ ConstructorMetadataAnnotation
+ type: IntrospectDeclarationsPhaseMacro
superclass: B
class B
metadata
@@ -1924,10 +1960,14 @@
@IntrospectDeclarationsPhaseMacro(
withDetailsFor: {'A'},
+ withMetadata: true,
)
class X extends A {}
''', r'''
class X
+ metadata
+ ConstructorMetadataAnnotation
+ type: IntrospectDeclarationsPhaseMacro
superclass: A
class A
metadata
@@ -1954,10 +1994,14 @@
@IntrospectDeclarationsPhaseMacro(
withDetailsFor: {'A'},
+ withMetadata: true,
)
class X extends A {}
''', r'''
class X
+ metadata
+ ConstructorMetadataAnnotation
+ type: IntrospectDeclarationsPhaseMacro
superclass: A
class A
metadata
@@ -1984,10 +2028,14 @@
@IntrospectDeclarationsPhaseMacro(
withDetailsFor: {'A'},
+ withMetadata: true,
)
class X extends A {}
''', r'''
class X
+ metadata
+ ConstructorMetadataAnnotation
+ type: IntrospectDeclarationsPhaseMacro
superclass: A
class A
metadata
@@ -2088,10 +2136,14 @@
@IntrospectDeclarationsPhaseMacro(
withDetailsFor: {'A'},
+ withMetadata: true,
)
class X with A {}
''', r'''
class X
+ metadata
+ ConstructorMetadataAnnotation
+ type: IntrospectDeclarationsPhaseMacro
mixins
A
mixin A
@@ -2125,10 +2177,14 @@
@IntrospectDeclarationsPhaseMacro(
withDetailsFor: {'A'},
+ withMetadata: true,
)
class X with A {}
''', r'''
class X
+ metadata
+ ConstructorMetadataAnnotation
+ type: IntrospectDeclarationsPhaseMacro
mixins
A
mixin A
@@ -2166,10 +2222,14 @@
@IntrospectDeclarationsPhaseMacro(
withDetailsFor: {'A'},
+ withMetadata: true,
)
class X extends A {}
''', r'''
class X
+ metadata
+ ConstructorMetadataAnnotation
+ type: IntrospectDeclarationsPhaseMacro
superclass: A
mixin A
metadata
@@ -2195,10 +2255,14 @@
@IntrospectDeclarationsPhaseMacro(
withDetailsFor: {'A'},
+ withMetadata: true,
)
class X with A {}
''', r'''
class X
+ metadata
+ ConstructorMetadataAnnotation
+ type: IntrospectDeclarationsPhaseMacro
mixins
A
mixin A
@@ -3292,7 +3356,7 @@
test_class_metadata_constructor_named() async {
await _assertIntrospectText(r'''
-@IntrospectTypesPhaseMacro()
+@IntrospectTypesPhaseMacro(withMetadata: true)
@A.named(42)
class X {}
@@ -3304,6 +3368,8 @@
class X
metadata
ConstructorMetadataAnnotation
+ type: IntrospectTypesPhaseMacro
+ ConstructorMetadataAnnotation
type: A
constructorName: named
''');
@@ -3320,7 +3386,7 @@
await _assertIntrospectText(r'''
import 'a.dart';
-@IntrospectTypesPhaseMacro()
+@IntrospectTypesPhaseMacro(withMetadata: true)
@A.named(42)
class X {}
@@ -3328,6 +3394,8 @@
class X
metadata
ConstructorMetadataAnnotation
+ type: IntrospectTypesPhaseMacro
+ ConstructorMetadataAnnotation
type: A
constructorName: named
''');
@@ -3344,7 +3412,7 @@
await _assertIntrospectText(r'''
import 'a.dart' as prefix;
-@IntrospectTypesPhaseMacro()
+@IntrospectTypesPhaseMacro(withMetadata: true)
@prefix.A.named(42)
class X {}
@@ -3352,6 +3420,8 @@
class X
metadata
ConstructorMetadataAnnotation
+ type: IntrospectTypesPhaseMacro
+ ConstructorMetadataAnnotation
type: A
constructorName: named
''');
@@ -3359,7 +3429,7 @@
test_class_metadata_constructor_unnamed() async {
await _assertIntrospectText(r'''
-@IntrospectTypesPhaseMacro()
+@IntrospectTypesPhaseMacro(withMetadata: true)
@A(42)
class X {}
@@ -3371,6 +3441,8 @@
class X
metadata
ConstructorMetadataAnnotation
+ type: IntrospectTypesPhaseMacro
+ ConstructorMetadataAnnotation
type: A
''');
}
@@ -3386,7 +3458,7 @@
await _assertIntrospectText(r'''
import 'a.dart';
-@IntrospectTypesPhaseMacro()
+@IntrospectTypesPhaseMacro(withMetadata: true)
@A(42)
class X {}
@@ -3394,6 +3466,8 @@
class X
metadata
ConstructorMetadataAnnotation
+ type: IntrospectTypesPhaseMacro
+ ConstructorMetadataAnnotation
type: A
''');
}
@@ -3409,7 +3483,7 @@
await _assertIntrospectText(r'''
import 'a.dart' as prefix;
-@IntrospectTypesPhaseMacro()
+@IntrospectTypesPhaseMacro(withMetadata: true)
@prefix.A(42)
class X {}
@@ -3417,13 +3491,15 @@
class X
metadata
ConstructorMetadataAnnotation
+ type: IntrospectTypesPhaseMacro
+ ConstructorMetadataAnnotation
type: A
''');
}
test_class_metadata_identifier() async {
await _assertIntrospectText(r'''
-@IntrospectTypesPhaseMacro()
+@IntrospectTypesPhaseMacro(withMetadata: true)
@a1
@a2
class X {}
@@ -3433,6 +3509,8 @@
''', r'''
class X
metadata
+ ConstructorMetadataAnnotation
+ type: IntrospectTypesPhaseMacro
IdentifierMetadataAnnotation
identifier: a1
IdentifierMetadataAnnotation
@@ -3449,7 +3527,7 @@
await _assertIntrospectText(r'''
import 'a.dart';
-@IntrospectTypesPhaseMacro()
+@IntrospectTypesPhaseMacro(withMetadata: true)
@a1
@a2
class X {}
@@ -3457,6 +3535,8 @@
''', r'''
class X
metadata
+ ConstructorMetadataAnnotation
+ type: IntrospectTypesPhaseMacro
IdentifierMetadataAnnotation
identifier: a1
IdentifierMetadataAnnotation
@@ -3473,7 +3553,7 @@
await _assertIntrospectText(r'''
import 'a.dart' as prefix;
-@IntrospectTypesPhaseMacro()
+@IntrospectTypesPhaseMacro(withMetadata: true)
@prefix.a1
@prefix.a2
class X {}
@@ -3481,6 +3561,8 @@
''', r'''
class X
metadata
+ ConstructorMetadataAnnotation
+ type: IntrospectTypesPhaseMacro
IdentifierMetadataAnnotation
identifier: a1
IdentifierMetadataAnnotation
@@ -3535,7 +3617,7 @@
import 'a.dart';
class X {
- @IntrospectTypesPhaseMacro()
+ @IntrospectTypesPhaseMacro(withMetadata: true)
@a
void foo() {}
}
@@ -3544,6 +3626,8 @@
foo
flags: hasBody
metadata
+ ConstructorMetadataAnnotation
+ type: IntrospectTypesPhaseMacro
IdentifierMetadataAnnotation
identifier: a
returnType: void
@@ -3579,12 +3663,15 @@
import 'a.dart';
abstract class A {
- @IntrospectTypesPhaseMacro()
+ @IntrospectTypesPhaseMacro(withMetadata: true)
void foo({@a required int x}) {}
}
''', r'''
foo
flags: hasBody
+ metadata
+ ConstructorMetadataAnnotation
+ type: IntrospectTypesPhaseMacro
namedParameters
x
flags: isNamed isRequired
@@ -3624,12 +3711,15 @@
import 'a.dart';
abstract class A {
- @IntrospectTypesPhaseMacro()
+ @IntrospectTypesPhaseMacro(withMetadata: true)
void foo(@a int x) {}
}
''', r'''
foo
flags: hasBody
+ metadata
+ ConstructorMetadataAnnotation
+ type: IntrospectTypesPhaseMacro
positionalParameters
x
flags: isRequired
@@ -3721,10 +3811,13 @@
await _assertIntrospectText(r'''
import 'a.dart';
-@IntrospectTypesPhaseMacro()
+@IntrospectTypesPhaseMacro(withMetadata: true)
class A<@a T> {}
''', r'''
class A
+ metadata
+ ConstructorMetadataAnnotation
+ type: IntrospectTypesPhaseMacro
typeParameters
T
metadata
@@ -3870,13 +3963,15 @@
await _assertIntrospectText(r'''
import 'a.dart';
-@IntrospectTypesPhaseMacro()
+@IntrospectTypesPhaseMacro(withMetadata: true)
@a
mixin X {}
''', r'''
mixin X
metadata
+ ConstructorMetadataAnnotation
+ type: IntrospectTypesPhaseMacro
IdentifierMetadataAnnotation
identifier: a
''');