diff --git a/angel_orm_generator/lib/src/orm_build_context.dart b/angel_orm_generator/lib/src/orm_build_context.dart index 6f3b763a..5eab9712 100644 --- a/angel_orm_generator/lib/src/orm_build_context.dart +++ b/angel_orm_generator/lib/src/orm_build_context.dart @@ -21,7 +21,8 @@ Future buildOrmContext( bool autoIdAndDateFields, {bool heedExclude: true}) async { var buildCtx = await buildContext(clazz, annotation, buildStep, resolver, - autoSnakeCaseNames, autoIdAndDateFields); + autoSnakeCaseNames, autoIdAndDateFields, + heedExclude: heedExclude); var ormAnnotation = reviveORMAnnotation(annotation); var ctx = new OrmBuildContext( buildCtx, diff --git a/angel_orm_generator/lib/src/orm_generator.dart b/angel_orm_generator/lib/src/orm_generator.dart index 4fc2461f..acabc98f 100644 --- a/angel_orm_generator/lib/src/orm_generator.dart +++ b/angel_orm_generator/lib/src/orm_generator.dart @@ -1,20 +1,41 @@ +import 'dart:async'; + import 'package:analyzer/dart/element/element.dart'; import 'package:angel_orm/angel_orm.dart'; import 'package:build/build.dart'; +import 'package:code_builder/code_builder.dart' hide LibraryBuilder; import 'package:source_gen/source_gen.dart'; +import 'orm_build_context.dart'; + Builder ormBuilder(_) { return new LibraryBuilder(new OrmGenerator(), generatedExtension: '.orm.g.dart'); } +/// Builder that generates `.orm.g.dart`, with an abstract `FooOrm` class. class OrmGenerator extends GeneratorForAnnotation { + final bool autoSnakeCaseNames; + final bool autoIdAndDateFields; + + OrmGenerator({this.autoSnakeCaseNames, this.autoIdAndDateFields}); + @override - generateForAnnotatedElement( - Element element, ConstantReader annotation, BuildStep buildStep) { + Future generateForAnnotatedElement( + Element element, ConstantReader annotation, BuildStep buildStep) async { if (element is ClassElement) { + var ctx = await buildOrmContext(element, annotation, buildStep, + buildStep.resolver, autoSnakeCaseNames, autoIdAndDateFields); + var lib = buildOrmBaseLibrary(ctx); + return lib.accept(new DartEmitter()).toString(); } else { throw 'The @Orm() annotation can only be applied to classes.'; } } + + Library buildOrmBaseLibrary(OrmBuildContext ctx) { + return new Library((lib) { + + }); + } }