Skip to content

Commit

Permalink
Fix issue with setter names
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexios80 committed Nov 13, 2024
1 parent 50afc8a commit 5d58b64
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
8 changes: 3 additions & 5 deletions hive_generator/lib/src/builder/schema_migrator_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class SchemaMigratorBuilder implements Builder {
final schemaInfos = <_SchemaInfo>[];
for (final type in hiveTypes) {
final cls = getClass(type.element);
final className = cls.name;
final className = cls.displayName;
final library = type.element.library!;
final typeId = readTypeId(type.annotation);
final result = TypeAdapterGenerator.getAccessors(
Expand Down Expand Up @@ -213,9 +213,9 @@ class _SchemaInfo {
fieldName.startsWith('_') ? fieldName.substring(1) : fieldName;

final isInConstructor =
constructor.parameters.any((e) => e.name == publicFieldName);
constructor.parameters.any((e) => e.displayName == publicFieldName);
final publicAccessors =
accessors.where((e) => e.name == publicFieldName).toList();
accessors.where((e) => e.displayName == publicFieldName).toList();
final hasPublicSetter = publicAccessors.any((e) => e.isSetter);
final hasPublicGetter = publicAccessors.any((e) => e.isGetter);

Expand All @@ -242,8 +242,6 @@ class _SchemaInfo {
sanitizedFields[publicFieldName] = schema;
}

print('sanitizedFields: $sanitizedFields');

return schema.copyWith(fields: sanitizedFields);
}
}
9 changes: 2 additions & 7 deletions hive_generator/lib/src/generator/type_adapter_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,8 @@ class TypeAdapterGenerator extends GeneratorForAnnotation<HiveType> {
continue;
}

final name = accessor.name;
if (accessor.isSetter) {
// Remove '=' from setter name
accessorNames.add(name.substring(0, name.length - 1));
} else {
accessorNames.add(name);
}
// The display name does not have the trailing '=' for setters
accessorNames.add(accessor.displayName);
}
}

Expand Down

0 comments on commit 5d58b64

Please sign in to comment.