Skip to content

Commit

Permalink
Fix adapter instances naming (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitusortner authored Apr 3, 2019
1 parent 434f95b commit 7668a28
Show file tree
Hide file tree
Showing 9 changed files with 550 additions and 127 deletions.
18 changes: 9 additions & 9 deletions floor_generator/lib/writer/dao_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ class DaoWriter extends Writer {
final entities = insertionMethods.map((method) => method.entity).toSet();

for (final entity in entities) {
final name = entity.classElement.displayName;
final fieldName = '_${decapitalize(name)}InsertionAdapter';
final type = refer('InsertionAdapter<$name>');
final entityClassName = entity.classElement.displayName;
final fieldName = '_${decapitalize(entityClassName)}InsertionAdapter';
final type = refer('InsertionAdapter<$entityClassName>');

final field = Field((builder) => builder
..name = fieldName
Expand All @@ -108,9 +108,9 @@ class DaoWriter extends Writer {
final entities = updateMethods.map((method) => method.entity).toSet();

for (final entity in entities) {
final name = entity.classElement.displayName;
final fieldName = '_${decapitalize(name)}UpdateAdapter';
final type = refer('UpdateAdapter<$name>');
final entityClassName = entity.classElement.displayName;
final fieldName = '_${decapitalize(entityClassName)}UpdateAdapter';
final type = refer('UpdateAdapter<$entityClassName>');

final field = Field((builder) => builder
..name = fieldName
Expand All @@ -136,9 +136,9 @@ class DaoWriter extends Writer {
final entities = deleteMethods.map((method) => method.entity).toSet();

for (final entity in entities) {
final name = entity.classElement.displayName;
final fieldName = '_${decapitalize(name)}DeletionAdapter';
final type = refer('DeletionAdapter<$name>');
final entityClassName = entity.classElement.displayName;
final fieldName = '_${decapitalize(entityClassName)}DeletionAdapter';
final type = refer('DeletionAdapter<$entityClassName>');

final field = Field((builder) => builder
..name = fieldName
Expand Down
19 changes: 10 additions & 9 deletions floor_generator/lib/writer/deletion_method_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,45 @@ class DeletionMethodWriter implements Writer {

@nonNull
String _generateMethodBody() {
final entityName = decapitalize(_method.entity.name);
final entityClassName =
decapitalize(_method.entity.classElement.displayName);
final methodSignatureParameterName = _method.parameterElement.name;

if (_method.flattenedReturnType.isVoid) {
return _generateVoidReturnMethodBody(
methodSignatureParameterName,
entityName,
entityClassName,
);
} else {
// if not void then must be int return
return _generateIntReturnMethodBody(
methodSignatureParameterName,
entityName,
entityClassName,
);
}
}

@nonNull
String _generateVoidReturnMethodBody(
final String methodSignatureParameterName,
final String entityName,
final String entityClassName,
) {
if (_method.changesMultipleItems) {
return 'await _${entityName}DeletionAdapter.deleteList($methodSignatureParameterName);';
return 'await _${entityClassName}DeletionAdapter.deleteList($methodSignatureParameterName);';
} else {
return 'await _${entityName}DeletionAdapter.delete($methodSignatureParameterName);';
return 'await _${entityClassName}DeletionAdapter.delete($methodSignatureParameterName);';
}
}

@nonNull
String _generateIntReturnMethodBody(
final String methodSignatureParameterName,
final String entityName,
final String entityClassName,
) {
if (_method.changesMultipleItems) {
return 'return _${entityName}DeletionAdapter.deleteListAndReturnChangedRows($methodSignatureParameterName);';
return 'return _${entityClassName}DeletionAdapter.deleteListAndReturnChangedRows($methodSignatureParameterName);';
} else {
return 'return _${entityName}DeletionAdapter.deleteAndReturnChangedRows($methodSignatureParameterName);';
return 'return _${entityClassName}DeletionAdapter.deleteAndReturnChangedRows($methodSignatureParameterName);';
}
}
}
19 changes: 10 additions & 9 deletions floor_generator/lib/writer/insertion_method_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,45 @@ class InsertionMethodWriter implements Writer {

@nonNull
String _generateMethodBody() {
final decapitalizedEntityName = decapitalize(_method.entity.name);
final entityClassName =
decapitalize(_method.entity.classElement.displayName);
final methodSignatureParameterName = _method.parameterElement.displayName;

if (_method.flattenedReturnType.isVoid) {
return _generateVoidReturnMethodBody(
methodSignatureParameterName,
decapitalizedEntityName,
entityClassName,
);
} else {
// if not void then must be int return
return _generateIntReturnMethodBody(
methodSignatureParameterName,
decapitalizedEntityName,
entityClassName,
);
}
}

@nonNull
String _generateVoidReturnMethodBody(
final String methodSignatureParameterName,
final String entityName,
final String entityClassName,
) {
if (_method.changesMultipleItems) {
return 'await _${entityName}InsertionAdapter.insertList($methodSignatureParameterName, ${_method.onConflict});';
return 'await _${entityClassName}InsertionAdapter.insertList($methodSignatureParameterName, ${_method.onConflict});';
} else {
return 'await _${entityName}InsertionAdapter.insert($methodSignatureParameterName, ${_method.onConflict});';
return 'await _${entityClassName}InsertionAdapter.insert($methodSignatureParameterName, ${_method.onConflict});';
}
}

@nonNull
String _generateIntReturnMethodBody(
final String methodSignatureParameterName,
final String entityName,
final String entityClassName,
) {
if (_method.changesMultipleItems) {
return 'return _${entityName}InsertionAdapter.insertListAndReturnIds($methodSignatureParameterName, ${_method.onConflict});';
return 'return _${entityClassName}InsertionAdapter.insertListAndReturnIds($methodSignatureParameterName, ${_method.onConflict});';
} else {
return 'return _${entityName}InsertionAdapter.insertAndReturnId($methodSignatureParameterName, ${_method.onConflict});';
return 'return _${entityClassName}InsertionAdapter.insertAndReturnId($methodSignatureParameterName, ${_method.onConflict});';
}
}
}
19 changes: 10 additions & 9 deletions floor_generator/lib/writer/update_method_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,45 @@ class UpdateMethodWriter implements Writer {

@nonNull
String _generateMethodBody() {
final entityName = decapitalize(_method.entity.name);
final entityClassName =
decapitalize(_method.entity.classElement.displayName);
final methodSignatureParameterName = _method.parameterElement.displayName;

if (_method.flattenedReturnType.isVoid) {
return _generateVoidReturnMethodBody(
methodSignatureParameterName,
entityName,
entityClassName,
);
} else {
// if not void then must be int return
return _generateIntReturnMethodBody(
methodSignatureParameterName,
entityName,
entityClassName,
);
}
}

@nonNull
String _generateIntReturnMethodBody(
final String methodSignatureParameterName,
final String entityName,
final String entityClassName,
) {
if (_method.changesMultipleItems) {
return 'return _${entityName}UpdateAdapter.updateListAndReturnChangedRows($methodSignatureParameterName, ${_method.onConflict});';
return 'return _${entityClassName}UpdateAdapter.updateListAndReturnChangedRows($methodSignatureParameterName, ${_method.onConflict});';
} else {
return 'return _${entityName}UpdateAdapter.updateAndReturnChangedRows($methodSignatureParameterName, ${_method.onConflict});';
return 'return _${entityClassName}UpdateAdapter.updateAndReturnChangedRows($methodSignatureParameterName, ${_method.onConflict});';
}
}

@nonNull
String _generateVoidReturnMethodBody(
final String methodSignatureParameterName,
final String entityName,
final String entityClassName,
) {
if (_method.changesMultipleItems) {
return 'await _${entityName}UpdateAdapter.updateList($methodSignatureParameterName, ${_method.onConflict});';
return 'await _${entityClassName}UpdateAdapter.updateList($methodSignatureParameterName, ${_method.onConflict});';
} else {
return 'await _${entityName}UpdateAdapter.update($methodSignatureParameterName, ${_method.onConflict});';
return 'await _${entityClassName}UpdateAdapter.update($methodSignatureParameterName, ${_method.onConflict});';
}
}
}
Loading

0 comments on commit 7668a28

Please sign in to comment.