| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 library initialize.static_loader; | |
| 5 | |
| 6 import 'dart:collection' show Queue; | |
| 7 import 'package:initialize/initialize.dart'; | |
| 8 | |
| 9 /// This represents an annotation/declaration pair. | |
| 10 class InitEntry<T> { | |
| 11 /// The annotation instance. | |
| 12 final Initializer<T> meta; | |
| 13 | |
| 14 /// The target of the annotation to pass to initialize. | |
| 15 final T target; | |
| 16 | |
| 17 InitEntry(this.meta, this.target); | |
| 18 } | |
| 19 | |
| 20 /// Set of initializers that are invoked by `run`. This is initialized with | |
| 21 /// code automatically generated by the transformer. | |
| 22 Queue<InitEntry> initializers = new Queue<InitEntry>(); | |
| 23 | |
| 24 /// Returns initializer functions matching the supplied filters and removes them | |
| 25 /// from `initializers` so they won't be ran again. | |
| 26 Queue<Function> loadInitializers( | |
| 27 {List<Type> typeFilter, InitializerFilter customFilter, Uri from}) { | |
| 28 if (from != null) { | |
| 29 throw 'The `from` option is not supported in deploy mode.'; | |
| 30 } | |
| 31 Queue<Function> result = new Queue<Function>(); | |
| 32 | |
| 33 var matchesFilters = (initializer) { | |
| 34 if (typeFilter != null && | |
| 35 !typeFilter.any((t) => initializer.meta.runtimeType == t)) { | |
| 36 return false; | |
| 37 } | |
| 38 if (customFilter != null && !customFilter(initializer.meta)) { | |
| 39 return false; | |
| 40 } | |
| 41 return true; | |
| 42 }; | |
| 43 | |
| 44 result.addAll(initializers | |
| 45 .where(matchesFilters) | |
| 46 .map((i) => () => i.meta.initialize(i.target))); | |
| 47 | |
| 48 initializers.removeWhere(matchesFilters); | |
| 49 | |
| 50 return result; | |
| 51 } | |
| OLD | NEW |