Generates a copyWith
implementation for Dart classes in IntelliJ / Android Studio.
Instructions:
Position the cursor where you want to insert the copyWith
method.
Press CMD+N / CTRL+N to show the generate dialog (Alternatively, right click in the editor and select "Generate...")
Given the class:
class Book {
final String id;
final String name;
final String description;
final Author author;
// ... methods ...
}
The plugin will generate the following copyWith
method:
Book copyWith({String id, String name, String description, Author author}) {
return Book(
id: id ?? this.id,
name: name ?? this.name,
description: description ?? this.description,
author: author ?? this.author,
);
}
Most of these are not an issue if you're following Dart's coding conventions. Mentioned for completeness:
final String foo; final String bar;
String foo = "hello"
.Adding some unit tests for CopyWithMethodGenerator.kt would be great, in particular to be able to test without having to touch anything plugin related.
The parsing definitely could be smarter, to generate something similar to an AST, perhaps. For now the parsing is very simple and regex based. This is probably enough for this small plugin though.