From 41fc6395ff7870106777c5ca258d852422e7e952 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Fri, 24 Aug 2018 09:47:37 -0400 Subject: [PATCH] Add stub code for generator --- .../lib/src/orm_build_context.dart | 3 ++- .../lib/src/orm_generator.dart | 25 +++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) 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) { + + }); + } }