Pedantic lints
This commit is contained in:
parent
ad7939b904
commit
5386722df3
13 changed files with 66 additions and 65 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
include: package:pedantic/analysis_options.yaml
|
||||||
analyzer:
|
analyzer:
|
||||||
strong-mode:
|
strong-mode:
|
||||||
implicit-casts: false
|
implicit-casts: false
|
|
@ -5,7 +5,7 @@ import 'package:angel_container/mirrors.dart';
|
||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
// Create a container instance.
|
// Create a container instance.
|
||||||
var container = new Container(const MirrorsReflector());
|
var container = Container(const MirrorsReflector());
|
||||||
|
|
||||||
// Register a singleton.
|
// Register a singleton.
|
||||||
container.registerSingleton<Engine>(Engine(40));
|
container.registerSingleton<Engine>(Engine(40));
|
||||||
|
|
|
@ -19,7 +19,7 @@ class Container {
|
||||||
///
|
///
|
||||||
/// Use this to create children of a global "scope."
|
/// Use this to create children of a global "scope."
|
||||||
Container createChild() {
|
Container createChild() {
|
||||||
return new Container._child(this);
|
return Container._child(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determines if the container has an injection of the given type.
|
/// Determines if the container has an injection of the given type.
|
||||||
|
@ -61,7 +61,7 @@ class Container {
|
||||||
/// `Future<T>` or `T`.
|
/// `Future<T>` or `T`.
|
||||||
Future<T> makeAsync<T>([Type type]) {
|
Future<T> makeAsync<T>([Type type]) {
|
||||||
type ??= T;
|
type ??= T;
|
||||||
Type futureType = null; //.Future<T>.value(null).runtimeType;
|
Type futureType; //.Future<T>.value(null).runtimeType;
|
||||||
|
|
||||||
if (T == dynamic) {
|
if (T == dynamic) {
|
||||||
try {
|
try {
|
||||||
|
@ -78,7 +78,7 @@ class Container {
|
||||||
} else if (futureType != null) {
|
} else if (futureType != null) {
|
||||||
return make(futureType);
|
return make(futureType);
|
||||||
} else {
|
} else {
|
||||||
throw new ReflectionException(
|
throw ReflectionException(
|
||||||
'No injection for Future<$type> or $type was found.');
|
'No injection for Future<$type> or $type was found.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ class Container {
|
||||||
|
|
||||||
var constructor = reflectedType.constructors.firstWhere(
|
var constructor = reflectedType.constructors.firstWhere(
|
||||||
(c) => isDefault(c.name),
|
(c) => isDefault(c.name),
|
||||||
orElse: () => throw new ReflectionException(
|
orElse: () => throw ReflectionException(
|
||||||
'${reflectedType.name} has no default constructor, and therefore cannot be instantiated.'));
|
'${reflectedType.name} has no default constructor, and therefore cannot be instantiated.'));
|
||||||
|
|
||||||
for (var param in constructor.parameters) {
|
for (var param in constructor.parameters) {
|
||||||
|
@ -133,7 +133,7 @@ class Container {
|
||||||
positional,
|
positional,
|
||||||
named, []).reflectee as T;
|
named, []).reflectee as T;
|
||||||
} else {
|
} else {
|
||||||
throw new ReflectionException(
|
throw ReflectionException(
|
||||||
'$type is not a class, and therefore cannot be instantiated.');
|
'$type is not a class, and therefore cannot be instantiated.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,7 @@ class Container {
|
||||||
as ??= T;
|
as ??= T;
|
||||||
|
|
||||||
if (_factories.containsKey(as)) {
|
if (_factories.containsKey(as)) {
|
||||||
throw new StateError('This container already has a factory for $as.');
|
throw StateError('This container already has a factory for $as.');
|
||||||
}
|
}
|
||||||
|
|
||||||
_factories[as] = f;
|
_factories[as] = f;
|
||||||
|
@ -166,7 +166,7 @@ class Container {
|
||||||
as ??= T == dynamic ? as : T;
|
as ??= T == dynamic ? as : T;
|
||||||
|
|
||||||
if (_singletons.containsKey(as ?? object.runtimeType)) {
|
if (_singletons.containsKey(as ?? object.runtimeType)) {
|
||||||
throw new StateError(
|
throw StateError(
|
||||||
'This container already has a singleton for ${as ?? object.runtimeType}.');
|
'This container already has a singleton for ${as ?? object.runtimeType}.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ class Container {
|
||||||
} else if (_parent != null) {
|
} else if (_parent != null) {
|
||||||
return _parent.findByName<T>(name);
|
return _parent.findByName<T>(name);
|
||||||
} else {
|
} else {
|
||||||
throw new StateError(
|
throw StateError(
|
||||||
'This container does not have a singleton named "$name".');
|
'This container does not have a singleton named "$name".');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,8 +196,7 @@ class Container {
|
||||||
/// to enable injecting multiple instances of a type within the same container hierarchy.
|
/// to enable injecting multiple instances of a type within the same container hierarchy.
|
||||||
void registerNamedSingleton<T>(String name, T object) {
|
void registerNamedSingleton<T>(String name, T object) {
|
||||||
if (_namedSingletons.containsKey(name)) {
|
if (_namedSingletons.containsKey(name)) {
|
||||||
throw new StateError(
|
throw StateError('This container already has a singleton named "$name".');
|
||||||
'This container already has a singleton named "$name".');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_namedSingletons[name] = object;
|
_namedSingletons[name] = object;
|
||||||
|
|
|
@ -8,7 +8,7 @@ final Map<Symbol, String> _symbolNames = <Symbol, String>{};
|
||||||
/// Use this in contexts where you know you won't need any reflective capabilities.
|
/// Use this in contexts where you know you won't need any reflective capabilities.
|
||||||
class EmptyReflector extends Reflector {
|
class EmptyReflector extends Reflector {
|
||||||
/// A [RegExp] that can be used to extract the name of a symbol without reflection.
|
/// A [RegExp] that can be used to extract the name of a symbol without reflection.
|
||||||
static final RegExp symbolRegex = new RegExp(r'Symbol\("([^"]+)"\)');
|
static final RegExp symbolRegex = RegExp(r'Symbol\("([^"]+)"\)');
|
||||||
|
|
||||||
const EmptyReflector();
|
const EmptyReflector();
|
||||||
|
|
||||||
|
@ -47,13 +47,13 @@ class _EmptyReflectedClass extends ReflectedClass {
|
||||||
const <ReflectedInstance>[],
|
const <ReflectedInstance>[],
|
||||||
const <ReflectedFunction>[],
|
const <ReflectedFunction>[],
|
||||||
const <ReflectedDeclaration>[],
|
const <ReflectedDeclaration>[],
|
||||||
dynamic);
|
Object);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ReflectedInstance newInstance(
|
ReflectedInstance newInstance(
|
||||||
String constructorName, List positionalArguments,
|
String constructorName, List positionalArguments,
|
||||||
[Map<String, dynamic> namedArguments, List<Type> typeArguments]) {
|
[Map<String, dynamic> namedArguments, List<Type> typeArguments]) {
|
||||||
throw new UnsupportedError(
|
throw UnsupportedError(
|
||||||
'Classes reflected via an EmptyReflector cannot be instantiated.');
|
'Classes reflected via an EmptyReflector cannot be instantiated.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,13 +70,13 @@ class _EmptyReflectedClass extends ReflectedClass {
|
||||||
|
|
||||||
class _EmptyReflectedType extends ReflectedType {
|
class _EmptyReflectedType extends ReflectedType {
|
||||||
const _EmptyReflectedType()
|
const _EmptyReflectedType()
|
||||||
: super('(empty)', const <ReflectedTypeParameter>[], dynamic);
|
: super('(empty)', const <ReflectedTypeParameter>[], Object);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ReflectedInstance newInstance(
|
ReflectedInstance newInstance(
|
||||||
String constructorName, List positionalArguments,
|
String constructorName, List positionalArguments,
|
||||||
[Map<String, dynamic> namedArguments, List<Type> typeArguments]) {
|
[Map<String, dynamic> namedArguments, List<Type> typeArguments]) {
|
||||||
throw new UnsupportedError(
|
throw UnsupportedError(
|
||||||
'Types reflected via an EmptyReflector cannot be instantiated.');
|
'Types reflected via an EmptyReflector cannot be instantiated.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ class _EmptyReflectedInstance extends ReflectedInstance {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ReflectedInstance getField(String name) {
|
ReflectedInstance getField(String name) {
|
||||||
throw new UnsupportedError(
|
throw UnsupportedError(
|
||||||
'Instances reflected via an EmptyReflector cannot call getField().');
|
'Instances reflected via an EmptyReflector cannot call getField().');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ class _EmptyReflectedFunction extends ReflectedFunction {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ReflectedInstance invoke(Invocation invocation) {
|
ReflectedInstance invoke(Invocation invocation) {
|
||||||
throw new UnsupportedError(
|
throw UnsupportedError(
|
||||||
'Instances reflected via an EmptyReflector cannot call invoke().');
|
'Instances reflected via an EmptyReflector cannot call invoke().');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,16 +17,16 @@ class MirrorsReflector extends Reflector {
|
||||||
var mirror = dart.reflectType(clazz);
|
var mirror = dart.reflectType(clazz);
|
||||||
|
|
||||||
if (mirror is dart.ClassMirror) {
|
if (mirror is dart.ClassMirror) {
|
||||||
return new _ReflectedClassMirror(mirror);
|
return _ReflectedClassMirror(mirror);
|
||||||
} else {
|
} else {
|
||||||
throw new ArgumentError('$clazz is not a class.');
|
throw ArgumentError('$clazz is not a class.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ReflectedFunction reflectFunction(Function function) {
|
ReflectedFunction reflectFunction(Function function) {
|
||||||
var closure = dart.reflect(function) as dart.ClosureMirror;
|
var closure = dart.reflect(function) as dart.ClosureMirror;
|
||||||
return new _ReflectedMethodMirror(closure.function, closure);
|
return _ReflectedMethodMirror(closure.function, closure);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -37,9 +37,9 @@ class MirrorsReflector extends Reflector {
|
||||||
return reflectType(dynamic);
|
return reflectType(dynamic);
|
||||||
} else {
|
} else {
|
||||||
if (mirror is dart.ClassMirror) {
|
if (mirror is dart.ClassMirror) {
|
||||||
return new _ReflectedClassMirror(mirror);
|
return _ReflectedClassMirror(mirror);
|
||||||
} else {
|
} else {
|
||||||
return new _ReflectedTypeMirror(mirror);
|
return _ReflectedTypeMirror(mirror);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ class MirrorsReflector extends Reflector {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ReflectedInstance reflectInstance(Object object) {
|
ReflectedInstance reflectInstance(Object object) {
|
||||||
return new _ReflectedInstanceMirror(dart.reflect(object));
|
return _ReflectedInstanceMirror(dart.reflect(object));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ class _ReflectedTypeMirror extends ReflectedType {
|
||||||
: super(
|
: super(
|
||||||
dart.MirrorSystem.getName(mirror.simpleName),
|
dart.MirrorSystem.getName(mirror.simpleName),
|
||||||
mirror.typeVariables
|
mirror.typeVariables
|
||||||
.map((m) => new _ReflectedTypeParameter(m))
|
.map((m) => _ReflectedTypeParameter(m))
|
||||||
.toList(),
|
.toList(),
|
||||||
mirror.reflectedType,
|
mirror.reflectedType,
|
||||||
);
|
);
|
||||||
|
@ -100,7 +100,7 @@ class _ReflectedTypeMirror extends ReflectedType {
|
||||||
ReflectedInstance newInstance(
|
ReflectedInstance newInstance(
|
||||||
String constructorName, List positionalArguments,
|
String constructorName, List positionalArguments,
|
||||||
[Map<String, dynamic> namedArguments, List<Type> typeArguments]) {
|
[Map<String, dynamic> namedArguments, List<Type> typeArguments]) {
|
||||||
throw new ReflectionException(
|
throw ReflectionException(
|
||||||
'$name is not a class, and therefore cannot be instantiated.');
|
'$name is not a class, and therefore cannot be instantiated.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ class _ReflectedClassMirror extends ReflectedClass {
|
||||||
: super(
|
: super(
|
||||||
dart.MirrorSystem.getName(mirror.simpleName),
|
dart.MirrorSystem.getName(mirror.simpleName),
|
||||||
mirror.typeVariables
|
mirror.typeVariables
|
||||||
.map((m) => new _ReflectedTypeParameter(m))
|
.map((m) => _ReflectedTypeParameter(m))
|
||||||
.toList(),
|
.toList(),
|
||||||
[],
|
[],
|
||||||
[],
|
[],
|
||||||
|
@ -127,7 +127,7 @@ class _ReflectedClassMirror extends ReflectedClass {
|
||||||
var value = mirror.declarations[key];
|
var value = mirror.declarations[key];
|
||||||
|
|
||||||
if (value is dart.MethodMirror && value.isConstructor) {
|
if (value is dart.MethodMirror && value.isConstructor) {
|
||||||
out.add(new _ReflectedMethodMirror(value));
|
out.add(_ReflectedMethodMirror(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ class _ReflectedClassMirror extends ReflectedClass {
|
||||||
var value = mirror.declarations[key];
|
var value = mirror.declarations[key];
|
||||||
|
|
||||||
if (value is dart.MethodMirror && !value.isConstructor) {
|
if (value is dart.MethodMirror && !value.isConstructor) {
|
||||||
out.add(new _ReflectedDeclarationMirror(
|
out.add(_ReflectedDeclarationMirror(
|
||||||
dart.MirrorSystem.getName(key), value));
|
dart.MirrorSystem.getName(key), value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ class _ReflectedClassMirror extends ReflectedClass {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<ReflectedInstance> get annotations =>
|
List<ReflectedInstance> get annotations =>
|
||||||
mirror.metadata.map((m) => new _ReflectedInstanceMirror(m)).toList();
|
mirror.metadata.map((m) => _ReflectedInstanceMirror(m)).toList();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<ReflectedFunction> get constructors => _constructorsOf(mirror);
|
List<ReflectedFunction> get constructors => _constructorsOf(mirror);
|
||||||
|
@ -171,8 +171,8 @@ class _ReflectedClassMirror extends ReflectedClass {
|
||||||
ReflectedInstance newInstance(
|
ReflectedInstance newInstance(
|
||||||
String constructorName, List positionalArguments,
|
String constructorName, List positionalArguments,
|
||||||
[Map<String, dynamic> namedArguments, List<Type> typeArguments]) {
|
[Map<String, dynamic> namedArguments, List<Type> typeArguments]) {
|
||||||
return new _ReflectedInstanceMirror(
|
return _ReflectedInstanceMirror(
|
||||||
mirror.newInstance(new Symbol(constructorName), positionalArguments));
|
mirror.newInstance(Symbol(constructorName), positionalArguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -192,19 +192,19 @@ class _ReflectedDeclarationMirror extends ReflectedDeclaration {
|
||||||
bool get isStatic => mirror.isStatic;
|
bool get isStatic => mirror.isStatic;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ReflectedFunction get function => new _ReflectedMethodMirror(mirror);
|
ReflectedFunction get function => _ReflectedMethodMirror(mirror);
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ReflectedInstanceMirror extends ReflectedInstance {
|
class _ReflectedInstanceMirror extends ReflectedInstance {
|
||||||
final dart.InstanceMirror mirror;
|
final dart.InstanceMirror mirror;
|
||||||
|
|
||||||
_ReflectedInstanceMirror(this.mirror)
|
_ReflectedInstanceMirror(this.mirror)
|
||||||
: super(new _ReflectedClassMirror(mirror.type),
|
: super(_ReflectedClassMirror(mirror.type),
|
||||||
new _ReflectedClassMirror(mirror.type), mirror.reflectee);
|
_ReflectedClassMirror(mirror.type), mirror.reflectee);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ReflectedInstance getField(String name) {
|
ReflectedInstance getField(String name) {
|
||||||
return new _ReflectedInstanceMirror(mirror.getField(new Symbol(name)));
|
return _ReflectedInstanceMirror(mirror.getField(Symbol(name)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ class _ReflectedMethodMirror extends ReflectedFunction {
|
||||||
dart.MirrorSystem.getName(mirror.simpleName),
|
dart.MirrorSystem.getName(mirror.simpleName),
|
||||||
<ReflectedTypeParameter>[],
|
<ReflectedTypeParameter>[],
|
||||||
mirror.metadata
|
mirror.metadata
|
||||||
.map((mirror) => new _ReflectedInstanceMirror(mirror))
|
.map((mirror) => _ReflectedInstanceMirror(mirror))
|
||||||
.toList(),
|
.toList(),
|
||||||
!mirror.returnType.hasReflectedType
|
!mirror.returnType.hasReflectedType
|
||||||
? const MirrorsReflector().reflectType(dynamic)
|
? const MirrorsReflector().reflectType(dynamic)
|
||||||
|
@ -228,10 +228,10 @@ class _ReflectedMethodMirror extends ReflectedFunction {
|
||||||
mirror.isSetter);
|
mirror.isSetter);
|
||||||
|
|
||||||
static ReflectedParameter _reflectParameter(dart.ParameterMirror mirror) {
|
static ReflectedParameter _reflectParameter(dart.ParameterMirror mirror) {
|
||||||
return new ReflectedParameter(
|
return ReflectedParameter(
|
||||||
dart.MirrorSystem.getName(mirror.simpleName),
|
dart.MirrorSystem.getName(mirror.simpleName),
|
||||||
mirror.metadata
|
mirror.metadata
|
||||||
.map((mirror) => new _ReflectedInstanceMirror(mirror))
|
.map((mirror) => _ReflectedInstanceMirror(mirror))
|
||||||
.toList(),
|
.toList(),
|
||||||
const MirrorsReflector().reflectType(mirror.type.reflectedType),
|
const MirrorsReflector().reflectType(mirror.type.reflectedType),
|
||||||
!mirror.isOptional,
|
!mirror.isOptional,
|
||||||
|
@ -241,11 +241,11 @@ class _ReflectedMethodMirror extends ReflectedFunction {
|
||||||
@override
|
@override
|
||||||
ReflectedInstance invoke(Invocation invocation) {
|
ReflectedInstance invoke(Invocation invocation) {
|
||||||
if (closureMirror == null) {
|
if (closureMirror == null) {
|
||||||
throw new StateError(
|
throw StateError(
|
||||||
'This object was reflected without a ClosureMirror, and therefore cannot be directly invoked.');
|
'This object was reflected without a ClosureMirror, and therefore cannot be directly invoked.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return new _ReflectedInstanceMirror(closureMirror.invoke(
|
return _ReflectedInstanceMirror(closureMirror.invoke(
|
||||||
invocation.memberName,
|
invocation.memberName,
|
||||||
invocation.positionalArguments,
|
invocation.positionalArguments,
|
||||||
invocation.namedArguments));
|
invocation.namedArguments));
|
||||||
|
|
|
@ -15,7 +15,7 @@ abstract class Reflector {
|
||||||
ReflectedInstance reflectInstance(Object object);
|
ReflectedInstance reflectInstance(Object object);
|
||||||
|
|
||||||
ReflectedType reflectFutureOf(Type type) {
|
ReflectedType reflectFutureOf(Type type) {
|
||||||
throw new UnsupportedError('`reflectFutureOf` requires `dart:mirrors`.');
|
throw UnsupportedError('`reflectFutureOf` requires `dart:mirrors`.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,15 +10,15 @@ class StaticReflector extends Reflector {
|
||||||
final Map<Object, ReflectedInstance> instances;
|
final Map<Object, ReflectedInstance> instances;
|
||||||
|
|
||||||
const StaticReflector(
|
const StaticReflector(
|
||||||
{this.names: const {},
|
{this.names = const {},
|
||||||
this.types: const {},
|
this.types = const {},
|
||||||
this.functions: const {},
|
this.functions = const {},
|
||||||
this.instances: const {}});
|
this.instances = const {}});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String getName(Symbol symbol) {
|
String getName(Symbol symbol) {
|
||||||
if (!names.containsKey(symbol)) {
|
if (!names.containsKey(symbol)) {
|
||||||
throw new ArgumentError(
|
throw ArgumentError(
|
||||||
'The value of $symbol is unknown - it was not generated.');
|
'The value of $symbol is unknown - it was not generated.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ class StaticReflector extends Reflector {
|
||||||
@override
|
@override
|
||||||
ReflectedFunction reflectFunction(Function function) {
|
ReflectedFunction reflectFunction(Function function) {
|
||||||
if (!functions.containsKey(function)) {
|
if (!functions.containsKey(function)) {
|
||||||
throw new ArgumentError(
|
throw ArgumentError(
|
||||||
'There is no reflection information available about $function.');
|
'There is no reflection information available about $function.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ class StaticReflector extends Reflector {
|
||||||
@override
|
@override
|
||||||
ReflectedInstance reflectInstance(Object object) {
|
ReflectedInstance reflectInstance(Object object) {
|
||||||
if (!instances.containsKey(object)) {
|
if (!instances.containsKey(object)) {
|
||||||
throw new ArgumentError(
|
throw ArgumentError(
|
||||||
'There is no reflection information available about $object.');
|
'There is no reflection information available about $object.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ class StaticReflector extends Reflector {
|
||||||
@override
|
@override
|
||||||
ReflectedType reflectType(Type type) {
|
ReflectedType reflectType(Type type) {
|
||||||
if (!types.containsKey(type)) {
|
if (!types.containsKey(type)) {
|
||||||
throw new ArgumentError(
|
throw ArgumentError(
|
||||||
'There is no reflection information available about $type.');
|
'There is no reflection information available about $type.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: angel_container
|
name: angel_container
|
||||||
version: 1.0.4
|
version: 1.1.0
|
||||||
author: Tobe O <thosakwe@gmail.com>
|
author: Tobe O <thosakwe@gmail.com>
|
||||||
description: "A better IoC container and dependency injector for Angel, ultimately allowing Angel to be used without dart:mirrors."
|
description: "A better IoC container and dependency injector for Angel, ultimately allowing Angel to be used without dart:mirrors."
|
||||||
homepage: https://github.com/angel-dart/container.git
|
homepage: https://github.com/angel-dart/container.git
|
||||||
|
@ -9,4 +9,5 @@ dependencies:
|
||||||
collection: ^1.0.0
|
collection: ^1.0.0
|
||||||
quiver: ^2.0.0
|
quiver: ^2.0.0
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
test:
|
pedantic: ^1.0.0
|
||||||
|
test: ^1.0.0
|
|
@ -6,11 +6,11 @@ import 'package:test/test.dart';
|
||||||
void returnVoidFromAFunction(int x) {}
|
void returnVoidFromAFunction(int x) {}
|
||||||
|
|
||||||
void testReflector(Reflector reflector) {
|
void testReflector(Reflector reflector) {
|
||||||
var blaziken = new Pokemon('Blaziken', PokemonType.fire);
|
var blaziken = Pokemon('Blaziken', PokemonType.fire);
|
||||||
Container container;
|
Container container;
|
||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
container = new Container(reflector);
|
container = Container(reflector);
|
||||||
container.registerSingleton(blaziken);
|
container.registerSingleton(blaziken);
|
||||||
container.registerFactory<Future<int>>((_) async => 46);
|
container.registerFactory<Future<int>>((_) async => 46);
|
||||||
});
|
});
|
||||||
|
@ -108,7 +108,7 @@ class Pokemon {
|
||||||
Pokemon(this.name, this.type);
|
Pokemon(this.name, this.type);
|
||||||
|
|
||||||
factory Pokemon.changeName(Pokemon other, String name) {
|
factory Pokemon.changeName(Pokemon other, String name) {
|
||||||
return new Pokemon(name, other.type);
|
return Pokemon(name, other.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -103,13 +103,13 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('cannot invoke', () {
|
test('cannot invoke', () {
|
||||||
var invocation = new Invocation.method(#drive, []);
|
var invocation = Invocation.method(#drive, []);
|
||||||
expect(() => mirror.invoke(invocation), throwsUnsupportedError);
|
expect(() => mirror.invoke(invocation), throwsUnsupportedError);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
group('reflectInstance', () {
|
group('reflectInstance', () {
|
||||||
var mirror = reflector.reflectInstance(new Truck());
|
var mirror = reflector.reflectInstance(Truck());
|
||||||
|
|
||||||
test('reflectee returns null', () {
|
test('reflectee returns null', () {
|
||||||
expect(mirror.reflectee, null);
|
expect(mirror.reflectee, null);
|
||||||
|
|
|
@ -5,11 +5,11 @@ void main() {
|
||||||
Container container;
|
Container container;
|
||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
container = new Container(const EmptyReflector())
|
container = Container(const EmptyReflector())
|
||||||
..registerSingleton<Song>(new Song(title: 'I Wish'))
|
..registerSingleton<Song>(Song(title: 'I Wish'))
|
||||||
..registerNamedSingleton('foo', 1)
|
..registerNamedSingleton('foo', 1)
|
||||||
..registerFactory<Artist>((container) {
|
..registerFactory<Artist>((container) {
|
||||||
return new Artist(
|
return Artist(
|
||||||
name: 'Stevie Wonder',
|
name: 'Stevie Wonder',
|
||||||
song: container.make<Song>(),
|
song: container.make<Song>(),
|
||||||
);
|
);
|
||||||
|
|
|
@ -3,8 +3,8 @@ import 'package:test/test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
test('returns the same instance', () {
|
test('returns the same instance', () {
|
||||||
var container = new Container(const EmptyReflector())
|
var container = Container(const EmptyReflector())
|
||||||
..registerLazySingleton<Dummy>((_) => new Dummy('a'));
|
..registerLazySingleton<Dummy>((_) => Dummy('a'));
|
||||||
|
|
||||||
var first = container.make<Dummy>();
|
var first = container.make<Dummy>();
|
||||||
expect(container.make<Dummy>(), first);
|
expect(container.make<Dummy>(), first);
|
||||||
|
|
|
@ -5,8 +5,8 @@ void main() {
|
||||||
Container container;
|
Container container;
|
||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
container = new Container(const EmptyReflector());
|
container = Container(const EmptyReflector());
|
||||||
container.registerNamedSingleton('foo', new Foo(bar: 'baz'));
|
container.registerNamedSingleton('foo', Foo(bar: 'baz'));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('fetch by name', () {
|
test('fetch by name', () {
|
||||||
|
@ -14,7 +14,7 @@ void main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('cannot redefine', () {
|
test('cannot redefine', () {
|
||||||
expect(() => container.registerNamedSingleton('foo', new Foo(bar: 'quux')),
|
expect(() => container.registerNamedSingleton('foo', Foo(bar: 'quux')),
|
||||||
throwsStateError);
|
throwsStateError);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue