zengen 0.2.0 copy "zengen: ^0.2.0" to clipboard
zengen: ^0.2.0 copied to clipboard

outdatedDart 1 only

A transformer to generate boilerplate code.

ZenGen #

This project provides a pub transformer to generate boilerplate code.

This library is inspired from the project Lombok in the Java world.

Warning #

Dart file modifications are not yet well integrated in the Dart editor.

If you run a web app use pub serve and launch dartium with localhost:8080 instead of Run in Dartium on your original file.

If you run a server app launch the built version of your dart file after a pub build instead of Run on your original file.

Features #

@ToString() #

Annotating a class with @ToString() will generate an implementation of String toString() built by default with its public getters.

For instance :

@ToString()
class A {
  final a;
  final int b;
  A(this.a, this.b);
}

will be transformed to :

@ToString()
class A {
  final a;
  final int b;
  A(this.a, this.b);
  @generated @override String toString() => "A(a=$a, b=$b)";
}

The code generated can be customized with the following optional parameters:

  • callSuper: if set to true the result of toString will contains the result of super.toString().
  • exclude: a list of getter names can be exclude with this argument.
  • includePrivate: if set to true the generation will include private getters.

@EqualsAndHashCode() #

Annotating a class with @EqualsAndHashCode() will generate an implementation of bool operator ==(o) and int get hashCode built by default with its public getters.

For instance :

@EqualsAndHashCode()
class A {
  final a;
  final int b;
  A(this.a, this.b);
}

will be transformed to :

@EqualsAndHashCode()
class A {
  final a;
  final int b;
  A(this.a, this.b);
  @generated @override int get hashCode => hashObjects([a, b]);
  @generated @override bool operator ==(o) => identical(this, o) || o.runtimeType == runtimeType && o.a == a && o.b == b;
}

The code generated can be customize with the following optional parameters:

  • callSuper: if set to true the generated code will use additionnally super.hashCode and super == o.
  • exclude: a list of getter names can be exclude with this argument.
  • includePrivate: if set to true the generation will include private getters.

@Delegate() #

Annotating a field/getter with @Delegate() will add to the enclosing class all the public methods available on the type of the field/getter.

For instance :

import 'package:zengen/zengen.dart';
abstract class A {
  m1();
}
class B {
  @Delegate() A _a;
}

will be transformed to :

import 'package:zengen/zengen.dart';
abstract class A {
  m1();
}
class B {
  @Delegate() A _a;
  @generated dynamic m1() => _a.m1();
}

The code generated can be customize with the following optional parameters:

  • exclude: a list of members can be exclude with this argument.

Usage #

To use this library in your code :

  • add a dependency in your pubspec.yaml :
dependencies:
  zengen: any
  • add the transformer in your pubspec.yaml :
transformers:
- zengen
  • add import in your dart code :
import 'package:zengen/zengen.dart';

License #

Apache 2.0

0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

A transformer to generate boilerplate code.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

barback, code_transformers, quiver

More

Packages that depend on zengen