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

Unified Diff: sky/specs/script.md

Issue 908263002: Specs: found a way to make @autorun work (Closed) Base URL: https://github.com/domokit/mojo.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/specs/modules.md ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/specs/script.md
diff --git a/sky/specs/script.md b/sky/specs/script.md
index 10d673bb119a8f45f28de7048209f7753ad7eecb..3b241991d66afdbc94763d23b93961b16fbe2f2d 100644
--- a/sky/specs/script.md
+++ b/sky/specs/script.md
@@ -36,13 +36,44 @@ The following definitions are exposed in ``sky:core``:
```dart
abstract class AutomaticMetadata {
const AutomaticMetadata();
- void init(DeclarationMirror target) { }
+ void init(DeclarationMirror target, Module module);
+
+ static void runLibrary(LibraryMirror library, Module module) {
+ library.declarations.values.toList()..sort((DeclarationMirror a, DeclarationMirror b) {
+ bool aHasLocation;
+ try {
+ aHasLocation = a.location != null;
+ } catch(e) {
+ aHasLocation = false;
+ }
+ bool bHasLocation;
+ try {
+ bHasLocation = b.location != null;
+ } catch(e) {
+ bHasLocation = false;
+ }
+ if (!aHasLocation)
+ return bHasLocation ? 1 : 0;
+ if (!bHasLocation)
+ return -1;
+ if (a.location.sourceUri != b.location.sourceUri)
+ return a.location.sourceUri.toString().compareTo(b.location.sourceUri.toString());
+ if (a.location.line != b.location.line)
+ return a.location.line - b.location.line;
+ return a.location.column - b.location.column;
+ })
+ ..forEach((DeclarationMirror d) {
+ d.metadata.forEach((InstanceMirror i) {
+ if (i.reflectee is AutomaticMetadata)
+ i.reflectee.run(d, module);
+ });
+ });
+ }
}
-/*
class AutomaticFunction extends AutomaticMetadata {
const AutomaticFunction();
- void init(DeclarationMirror target) {
+ void init(DeclarationMirror target, Module module) {
assert(target is MethodMirror);
MethodMirror f = target as MethodMirror;
assert(!f.isAbstract);
@@ -55,7 +86,6 @@ class AutomaticFunction extends AutomaticMetadata {
}
}
const autorun = const AutomaticFunction();
-*/
```
Extensions
« no previous file with comments | « sky/specs/modules.md ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698