ivnsch / dart_copy_with_plugin

Dart copyWith generation plugin
MIT License
8 stars 0 forks source link
android-studio-plugin dart intellij-plugin

Dart copyWith plugin

Generates a copyWith implementation for Dart classes in IntelliJ / Android Studio.

Instructions:

ScreenShot

Example:

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,
    );
}

Current limitations:

Most of these are not an issue if you're following Dart's coding conventions. Mentioned for completeness:

Contribute:

Adding some unit tests for CopyWithMethodGenerator.kt would be great, in particular to be able to test without having to touch anything plugin related.

Outlook:

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.