annotation_crawler 1.1.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 64

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

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

  • Dart: 2.0.0
  • pana: 0.12.4

Platforms

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.

Dependencies

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