Add stub code for generator
This commit is contained in:
parent
2ba124c12e
commit
41fc6395ff
2 changed files with 25 additions and 3 deletions
|
@ -21,7 +21,8 @@ Future<OrmBuildContext> 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,
|
||||
|
|
|
@ -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<ORM> {
|
||||
final bool autoSnakeCaseNames;
|
||||
final bool autoIdAndDateFields;
|
||||
|
||||
OrmGenerator({this.autoSnakeCaseNames, this.autoIdAndDateFields});
|
||||
|
||||
@override
|
||||
generateForAnnotatedElement(
|
||||
Element element, ConstantReader annotation, BuildStep buildStep) {
|
||||
Future<String> 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) {
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue