modelClassType

This commit is contained in:
Tobe O 2018-02-27 15:03:58 -05:00
parent f10b8ab21b
commit 36b24480b2
2 changed files with 19 additions and 1 deletions

View file

@ -69,6 +69,7 @@ class JsonModelGenerator extends GeneratorForAnnotation<Serializable> {
}
generateConstructor(ctx, clazz, file);
generateChangeMethod(ctx, clazz, file);
}));
}
@ -86,4 +87,15 @@ class JsonModelGenerator extends GeneratorForAnnotation<Serializable> {
}
}));
}
/// Generate a `change` method.
void generateChangeMethod(
BuildContext ctx, ClassBuilder clazz, FileBuilder file) {
clazz.methods.add(new Method((method) {
method
..name = 'change'
..returns = ctx.modelClassType
..requiredParameters.add(new Parameter());
}));
}
}

View file

@ -1,10 +1,12 @@
import 'package:analyzer/dart/element/element.dart';
import 'package:angel_serialize/angel_serialize.dart';
import 'package:code_builder/code_builder.dart';
import 'package:recase/recase.dart';
/// A base context for building serializable classes.
class BuildContext {
ReCase _modelClassNameRecase;
TypeReference _modelClassType;
/// A map of field names to resolved names from `@Alias()` declarations.
final Map<String, String> aliases = {};
@ -30,7 +32,11 @@ class BuildContext {
: originalClassName;
/// A [ReCase] instance reflecting on the [modelClassName].
ReCase get modelClassNameRecase => _modelClassNameRecase ??= new ReCase(modelClassName);
ReCase get modelClassNameRecase =>
_modelClassNameRecase ??= new ReCase(modelClassName);
TypeReference get modelClassType =>
_modelClassType ??= new TypeReference((b) => b.symbol = modelClassName);
/// The [FieldElement] pointing to the primary key.
FieldElement get primaryKeyField =>