unrequire pkg:meta

This commit is contained in:
Tobe O 2018-11-08 11:54:23 -05:00
parent feb489949a
commit b5237e9957
3 changed files with 47 additions and 35 deletions

View file

@ -7,7 +7,6 @@ environment:
sdk: ">=1.8.0 <3.0.0"
dependencies:
collection: ^1.0.0
meta: ^1.0.0
quiver: ^2.0.0
dev_dependencies:
test:

View file

@ -12,55 +12,71 @@ class ReflectorLibraryGenerator {
ReflectorLibraryGenerator(this.element, this.annotation);
String get reflectorClassName {
// Select the name
if (annotation.name?.isNotEmpty == true) {
return new ReCase(annotation.name).pascalCase + 'Reflector';
} else if (element.name?.isNotEmpty == true) {
var rc = new ReCase(element.name);
return rc.pascalCase + 'Reflector';
} else {
throw new StateError(
'A statically-generated Reflector must reside in a named library, or include the `name` attribute in @GenerateReflector().');
}
}
String get typeMapName => new ReCase(reflectorClassName).camelCase + 'Types';
String toSource() {
return generate().accept(new DartEmitter()).toString();
}
Library generate() {
return new Library((lib) {
lib.body.add(generateReflectorClass());
var clazz = generateReflectorClass();
// Generate a ReflectedClass for each type
var staticTypes = <String, Expression>{};
for (var type in annotation.types) {
if (type is InterfaceType) {
lib.body.add(generateReflectedClass(type));
var reflected = generateReflectedClass(type);
lib.body.add(reflected);
staticTypes[type.name] =
refer(reflected.name).constInstanceNamed('_', []);
} else {
// TODO: Handle these
}
}
clazz = clazz.rebuild((b) {
// Generate static values
b.fields.add(new Field((b) => b
..name = 'staticTypes'
..modifier = FieldModifier.constant
..static = true
..assignment = literalConstMap(staticTypes
.map((name, type) => new MapEntry(refer(name), type))).code));
});
lib.body.add(clazz);
});
}
Class generateReflectorClass() {
return new Class((clazz) {
// Select the name
if (annotation.name?.isNotEmpty == true) {
clazz.name = annotation.name;
} else {
var rc = new ReCase(element.name);
clazz.name = rc.pascalCase + 'Reflector';
}
clazz.name = reflectorClassName;
// implements Reflector
clazz
..extend = refer('StaticReflector')
..implements.add(refer('Reflector'));
// extends StaticReflector
clazz.extend = refer('StaticReflector');
// Add a const constructor
clazz.constructors.add(new Constructor((b) {
b..constant = true;
}));
// Add a reflectClass that just forwards to reflectType
clazz.methods.add(new Method((b) {
b
..name = 'reflectClass'
..returns = refer('ReflectedClass')
..annotations.add(refer('override'))
..requiredParameters.add(new Parameter((b) => b
..name = 'type'
..type = refer('Type')))
..body = new Code('return reflectType(type) as ReflectedClass;');
..constant = true
..initializers.add(
refer('super').call([], {'types': refer('staticTypes')}).code);
// TODO: Invoke super with static info
}));
});
}

View file

@ -6,16 +6,13 @@ part of angel_container_generator_test;
// AngelContainerGenerator
// **************************************************************************
class AngelContainerGeneratorTestReflector implements Reflector {
const AngelContainerGeneratorTestReflector();
@override
ReflectedClass reflectClass(Type type) {
return reflectType(type) as ReflectedClass;
}
}
class _ReflectedArtist extends ReflectedClass {
const _ReflectedArtist._()
: super('Artist', const [], const [], const [], const [], Artist);
}
class AngelContainerGeneratorTestReflector extends StaticReflector {
const AngelContainerGeneratorTestReflector() : super(types: staticTypes);
static const staticTypes = const {Artist: const _ReflectedArtist._()};
}