Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(548)

Side by Side Diff: README.md

Issue 923733002: Major refactor of the transformer, added an `InitializePlugin` class which allows you to hook direc… (Closed) Base URL: git@github.com:dart-lang/static-init.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 Initialize 1 Initialize
2 ========== 2 ==========
3 3
4 This package provides a common interface for initialization annotations on top 4 This package provides a common interface for initialization annotations on top
5 level methods, classes, and libraries. The interface looks like this: 5 level methods, classes, and libraries. The interface looks like this:
6 6
7 abstract class Initializer<T> { 7 abstract class Initializer<T> {
8 dynamic initialize(T target); 8 dynamic initialize(T target);
9 } 9 }
10 10
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 84
85 For classes which are stateless, you can usually just have a single const 85 For classes which are stateless, you can usually just have a single const
86 instance, and that is how the actual InitMethod implementation works. Simply add 86 instance, and that is how the actual InitMethod implementation works. Simply add
87 something like the following: 87 something like the following:
88 88
89 const initMethod = const InitMethod(); 89 const initMethod = const InitMethod();
90 90
91 Now when people use the annotation, it just looks like `@initMethod` without any 91 Now when people use the annotation, it just looks like `@initMethod` without any
92 parenthesis, and its a bit more efficient since there is a single instance. You 92 parenthesis, and its a bit more efficient since there is a single instance. You
93 can also make your class private to force users into using the static instance. 93 can also make your class private to force users into using the static instance.
94
95 ## Creating custom transformer plugins
96
97 It is possible to create a custom plugin for the initialize transformer which
98 allows you to have full control over what happens to your annotations at compile
99 time. Implement `InitializePlugin` class and pass that in to the
100 `InitializeTransformer` to make it take effect.
101
102 You will need to be familiar with the `analyzer` package in order to write these
103 plugins, but they can be extremely powerful. See the `DefaultInitializerPlugin`
104 in `lib/build/initializer_plugin.dart` as a reference. Chances are you may want
105 to extend that class in order to get a lot of the default functionality.
106
107 TODO: Add some examples here.
Siggi Cherem (dart-lang) 2015/02/13 00:50:36 I think the pointer above is good, not sure if we
jakemac 2015/02/13 20:16:05 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698