Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rrousselGit committed May 14, 2024
1 parent dfc3483 commit 4c96853
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions packages/freezed/lib/src/templates/copy_with.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,16 @@ ${_abstractDeepCopyMethods().join()}
String get abstractCopyWithGetter {
if (cloneableProperties.isEmpty) return '';

return '''
return _maybeOverride(
doc: '''
/// Create a copy of ${data.name}
/// with the given fields replaced by the non-null parameter values.
${_hasSuperClass ? '@override\n' : ''}@JsonKey(ignore: true)
''',
'''
@JsonKey(ignore: true)
$_abstractClassName${genericsParameter.append('$clonedClassName$genericsParameter')} get copyWith => throw $privConstUsedErrorVarName;
''';
''',
);
}

String get concreteCopyWithGetter {
Expand Down Expand Up @@ -361,8 +365,11 @@ $returnType get ${cloneableProperty.name} {
return '$name${cloneableProperty.genericParameters.append('\$Res')}';
}

String _maybeOverride(String res) {
return _hasSuperClass ? '@override $res' : res;
String _maybeOverride(
String res, {
String doc = '',
}) {
return _hasSuperClass ? '$doc@override $res' : '$doc$res';
}

String get _abstractClassName => interfaceNameFrom(clonedClassName);
Expand Down

0 comments on commit 4c96853

Please sign in to comment.