annotation_crawler 1.1.1

  • Example
  • Installing
  • Versions
  • 60

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.
// 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.
// 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);


  • Add implicit-casts: false and implicit-dynamics: false to analysis option to be strong mode safe


  • annotatedDeclarations now expects a Type as the on parameter: annotatedDeclarations(Foo, on: SomeClass);
  • Added a proper example to example/main.dart
  • Add CI tests for formatting and analysis


  • Fix README example


  • Started the changelog
  • Made this package dart 2.0 compatible


import 'dart:mirrors';

import 'package:annotation_crawler/annotation_crawler.dart';

class Author {
  final String name;
  const Author(;

class Scene {
  final int act;
  final int scene;
  const Scene({this.act, this.scene});

abstract class Play {
  final String name;


  void perform();

@Author('Arthur Miller')
class MajestyPlay extends Play {
  MajestyPlay() : super('Her majesty\'s Theater');

  perform() {

  @Scene(act: 1, scene: 1)
  void performAct1Scene1() => print('Performing play "$name" act 1 scene 1.');

  @Scene(act: 1, scene: 2)
  void performAct1Scene2() => print('Performing play "$name" act 1 scene 2.');

  @Scene(act: 2, scene: 1)
  void performAct2Scene1() => print('Performing play "$name" act 2 scene 1.');

void main() {
  // Perform all plays written by Arthur Miller.
      .where((decl) =>
          decl.declaration is ClassMirror &&
          decl.annotation == const Author("Arthur Miller"))
      .forEach((decl) {
    final ClassMirror playClass = decl.declaration;
    final Play play =
        playClass.newInstance(const Symbol(''), <dynamic>[]).reflectee;

  print('Now playing only act 2 scene 1:');

  final majestyPlay = new MajestyPlay();

  final declaration = annotatedDeclarations(Scene, on: majestyPlay.runtimeType)
      .singleWhere((decl) {
    final Scene scene = decl.annotation;
    return scene.act == 2 && scene.scene == 1;

  /// Invoke the found method on given object.
  reflect(majestyPlay).invoke(declaration.declaration.simpleName, <dynamic>[]);

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  annotation_crawler: ^1.1.1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:annotation_crawler/annotation_crawler.dart';
Version Uploaded Documentation Archive
1.1.1 Jul 19, 2018 Go to the documentation of annotation_crawler 1.1.1 Download annotation_crawler 1.1.1 archive
1.1.0 Jul 17, 2018 Go to the documentation of annotation_crawler 1.1.0 Download annotation_crawler 1.1.0 archive
1.0.1 Jul 17, 2018 Go to the documentation of annotation_crawler 1.0.1 Download annotation_crawler 1.0.1 archive
1.0.0 Jul 17, 2018 Go to the documentation of annotation_crawler 1.0.0 Download annotation_crawler 1.0.0 archive
0.1.0 May 11, 2014 Go to the documentation of annotation_crawler 0.1.0 Download annotation_crawler 0.1.0 archive
0.0.1 Apr 2, 2014 Go to the documentation of annotation_crawler 0.0.1 Download annotation_crawler 0.0.1 archive
0.0.1-dev Apr 2, 2014 Go to the documentation of annotation_crawler 0.0.1-dev Download annotation_crawler 0.0.1-dev archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7


Detected platforms: web, other

Primary library: package:annotation_crawler/annotation_crawler.dart with components: mirrors.

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >1.5.0 <3.0.0
Dev dependencies
test any