Skip to content

Commit 28b6746

Browse files
committed
centralize prefix logic
1 parent 85d4570 commit 28b6746

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

json_serializable/lib/src/json_serializable_generator.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class JsonSerializableGenerator
9696
});
9797

9898
if (classAnnotation.createToJson) {
99-
var prefix = '_\$${classElement.name}';
99+
var prefix = _prefix(classElement);
100100
var mixClassName = '${prefix}SerializerMixin';
101101
var helpClassName = '${prefix}JsonMapWrapper';
102102

@@ -165,11 +165,9 @@ class JsonSerializableGenerator
165165
});
166166

167167
if (classAnnotation.createFactory) {
168-
var prefix = '_\$${classElement.name}';
169-
170168
buffer.writeln();
171-
buffer.writeln('${classElement
172-
.name} ${prefix}FromJson(Map<String, dynamic> json) =>');
169+
buffer.writeln('${classElement.name} '
170+
'${_prefix(classElement)}FromJson(Map<String, dynamic> json) =>');
173171

174172
String deserializeFun(String paramOrFieldName,
175173
{ParameterElement ctorParam}) =>
@@ -396,6 +394,8 @@ class _TypeHelperContext implements SerializeContext, DeserializeContext {
396394
targetType, expression, _notSupportedWithTypeHelpersMsg));
397395
}
398396

397+
String _prefix(ClassElement classElement) => '_\$${classElement.name}';
398+
399399
String _safeNameAccess(FieldElement field) {
400400
var name = _jsonKeyFor(field).name ?? field.name;
401401
// TODO(kevmoo): JsonKey.name could also have quotes and other silly.

0 commit comments

Comments
 (0)