annotation_crawler 1.1.1

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

1.1.1 #

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

1.1.0 #

  • 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

1.0.1 #

  • Fix README example

1.0.0 #

  • Started the changelog
  • Made this package dart 2.0 compatible

example/main.dart

import 'dart:mirrors';

import 'package:annotation_crawler/annotation_crawler.dart';

class Author {
  final String name;
  const Author(this.name);
}

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

abstract class Play {
  final String name;

  Play(this.name);

  void perform();
}

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

  @override
  perform() {
    performAct1Scene1();
    performAct1Scene2();
    performAct2Scene1();
  }

  @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.
  annotatedDeclarations(Author)
      .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;
    play.perform();
  });

  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:


dependencies:
  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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
36
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
84
Overall:
Weighted score of the above. [more]
64
Learn more about scoring.

We analyzed this package on Sep 13, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21

Platforms

Detected platforms: web, other

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

Health suggestions

Fix lib/annotation_crawler.dart. (-1 points)

Analysis of lib/annotation_crawler.dart reported 2 hints:

line 59 col 29: Use = to separate a named parameter from its default value.

line 87 col 20: Use = to separate a named parameter from its default value.

Maintenance suggestions

Package is getting outdated. (-15.34 points)

The package was last published 60 weeks ago.

The package description is too short. (-1 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

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