|
| 1 | +import 'package:meta/meta.dart'; |
| 2 | +import 'package:meta/meta_meta.dart'; |
| 3 | + |
| 4 | +/// {@template hook_installer} |
| 5 | +/// An annotation indicating that the annotated method |
| 6 | +/// must be called in the constructor of the class |
| 7 | +/// that uses the mixin defining the method. |
| 8 | +/// |
| 9 | +/// If [concreteOnly] is true (default), the requirement |
| 10 | +/// applies only to concrete classes, and calling it in an abstract |
| 11 | +/// class's constructor is considered a violation. |
| 12 | +/// Otherwise, it applies to the class even if it's abstract. |
| 13 | +/// |
| 14 | +/// Note: If any class in the inheritance chain calls the |
| 15 | +/// annotated method in its constructor, the requirement |
| 16 | +/// is considered satisfied for subclasses. |
| 17 | +/// {@endtemplate} |
| 18 | +@Target({TargetKind.method}) |
| 19 | +@immutable |
| 20 | +class MustCallInConstructor { |
| 21 | + /// If true (default), the requirement |
| 22 | + /// applies only to concrete classes, and calling it in an abstract |
| 23 | + /// class's constructor is considered a violation. |
| 24 | + /// Otherwise, it applies to the class even if it's abstract. |
| 25 | + final bool concreteOnly; |
| 26 | + |
| 27 | + /// {@macro hook_installer} |
| 28 | + const MustCallInConstructor({this.concreteOnly = true}); |
| 29 | +} |
| 30 | + |
| 31 | +/// {@macro hook_installer} |
| 32 | +const mustCallInConstructor = MustCallInConstructor(); |
0 commit comments