Skip to content

Commit ccef473

Browse files
authored
clean up some out of date portions of the macro spec (#2003)
This was still pointing at my old repo instead of the new api, and referred to some older apis :). Removes all references to the prototype repo.
1 parent 89bebbd commit ccef473

File tree

1 file changed

+23
-28
lines changed

1 file changed

+23
-28
lines changed

working/macros/feature-specification.md

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,9 @@ regular Dart class declarations. They are macros by virtue of the fact that they
300300
implement one or more special "macro" interfaces defined by the Dart core
301301
libraries.
302302

303-
*Note: The API is still being designed, and is documented [here][docs].*
303+
*Note: The API is still being designed, and lives [here][api].*
304304

305-
[docs]: https://jakemac53.github.io/macro_prototype/doc/api/definition/definition-library.html
305+
[api]: https://github.com/dart-lang/language/blob/master/working/macros/api
306306

307307
Every macro interface is a subtype of a root [Macro][] [marker interface][].
308308
There are interfaces for each kind of declaration macros can be applied to:
@@ -312,47 +312,42 @@ implement as many of these interfaces as it wants to. This allows a single macro
312312
to participate in multiple phases and to support being applied to multiple kinds
313313
of declarations.
314314

315-
[Macro]: https://jakemac53.github.io/macro_prototype/doc/api/definition/Macro-class.html
315+
[Macro]: https://github.com/dart-lang/language/blob/master/working/macros/api/macros.dart
316316
[marker interface]: https://en.wikipedia.org/wiki/Marker_interface_pattern
317317

318318
Each macro interface declares a single method that the macro class must
319319
implement in order to apply the macro in a given phase on a given declaration.
320320
For example, a macro applied to classes in the declaration phase implements
321-
[ClassDeclarationMacro][] and its [`visitClassDeclaration()`][visit] method.
321+
`ClassDeclarationsMacro` and its `buildDeclarationsForClass` method.
322322

323-
[ClassDeclarationMacro]: https://jakemac53.github.io/macro_prototype/doc/api/definition/ClassDeclarationMacro-class.html
324-
325-
[visit]: https://jakemac53.github.io/macro_prototype/doc/api/definition/ClassDeclarationMacro/visitClassDeclaration.html
326-
327-
When a Dart implementation executes macros, it invokes these visit methods at
328-
the appropriate phase for the declarations the macro is applied to. Each visit
323+
When a Dart implementation executes macros, it invokes these builder methods at
324+
the appropriate phase for the declarations the macro is applied to. Each builder
329325
method is passed two arguments which give the macro the context and capabilities
330-
it needs to introspect over the program and generate code:
331-
332-
### Introspection argument
326+
it needs to introspect over the program and generate code.
333327

334-
The first argument to a visit method is an object that lets the macro introspect over the declaration that the macro is applied to. The type of this argument
335-
varies for each macro interface. Each kind of declaration has unique properties
336-
and the phases each have different introspective power.
328+
### Declaration argument
337329

338-
For example, in [ClassDeclarationMacro][], the introspection object is a
339-
[ClassDeclaration][]. That object gives you access to the name of the class,
340-
its supertypes, members, etc.
330+
The first argument to a builder method is an object describing the
331+
declaration it is applied to. This argument contains only essentially the parsed
332+
AST for the declaration itself, and does not include nested declarations.
341333

342-
[ClassDeclaration]: https://jakemac53.github.io/macro_prototype/doc/api/definition/ClassDeclaration-class.html
334+
For example, in `ClassDeclarationsMacro`, the introspection object is a
335+
`ClassDeclaration`. This gives you access to the name of the class and access
336+
to the immediate superclass, as well as any immediate mixins or interfaces,
337+
but _not_ its members or entire class hierarchy.
343338

344339
### Builder argument
345340

346-
The second argument is an instance of a "builder" class. It exposes methods
347-
that let the macro add code to and modify the declaration that the macro is
348-
applied to. As with the introspection object, each macro class has a different
349-
builder type whose capabilities vary based on phase.
341+
The second argument is an instance of a [builder][] class. It exposes both
342+
methods to contribute new code to the program, as well as phase specific
343+
introspection capabilities.
350344

351-
In [ClassDeclarationMacro][], the builder is a [ClassDeclarationBuilder][]. Its
352-
primary method is `addToClass()`, which the macro can call to add a new member
353-
to the class.
345+
In `ClassDeclarationsMacro`, the builder is a `ClassDeclarationBuilder`. Its
346+
primary method is `declareInClass`, which the macro can call to add a new member
347+
to the class. It also implements the `ClassIntrospector` interface, which allows
348+
you to get the members of the class, as well as its entire class hierarchy.
354349

355-
[ClassDeclarationBuilder]: https://jakemac53.github.io/macro_prototype/doc/api/definition/ClassDeclarationBuilder-class.html
350+
[builder]: https://github.com/dart-lang/language/blob/master/working/macros/api/builders.dart
356351

357352
### Introspecting on metadata annotations
358353

0 commit comments

Comments
 (0)