annotation_crawler 1.0.1
annotation_crawler: ^1.0.1 copied to clipboard
Helps finding classes or methods with specific annotations.
Annotation Crawler #
Helps finding annotated declarations in a particular scope.
The main functions to use in this library are:
// Returns a List of AnnotatedDeclaration for each top level declaration that has Foo as annotation.
annotatedDeclarations(Foo);
// Does the same, but only for declarations in SomeClass
annotatedDeclarations(Foo, on: SomeClass);
// Returns a List of ClassMirror for each class that has Foo as annotation.
findClasses(Foo);
// Returns a List of MethodMirror for each method on SomeClass that has Foo as annotation.
findMethodsOnClass(SomeClass, Foo);
// Returns a List of MethodMirror for each method on someObject that has Foo as annotation.
findMethodsOnInstance(someObject, Foo);
Usage #
import 'annotation_crawler';
main () {
// Perform all plays written by Arthur Miller.
annotatedDeclarations(Author)
.where((decl) => decl.declaration is ClassMirror &&
decl.annotation == const Author("Arthur Miller"))
.map((decl) => decl.declaration.newInstance(const Symbol(''), ['Her majesty's Theater']).reflectee)
.forEach(perform);
// Perform the first scence of ACT III of the Merchant of Venice.
var play = annotatedDeclarations(Title)
.where((decl) => decl.annotation.name = 'The Merchant of venice')
.single.declaration.newInstance(const Symbol(''), ['Her majesty\'s theater']);
MethodMirror scene = annotatedDeclarations(Scene, on: play.runtimeType)
.where((decl) => decl.annotation.act == 'III' &&
decl.annotation.scene == 'I')
.single;
perform(play.getField(scene.simpleName).reflectee);
}