toCode method

  1. @override
String toCode()
override

Transforms the BaseInstance or its implementation into Code (a String)

This makes testing rather easy, because the building blocs of a whole Code tree can be easily tested, but just testing the underlying types of instances. More complex impelementations of Instances can be based on the BaseInstances for which only the configuration (properties, etc) have to be unit tested since the toCode function is inherited.

Implementation

@override
String toCode() {
  final stringBuffer = StringBuffer()
    ..write(name)
    ..write('(')
    ..write(
      _propertiesToCode(),
    );

  if (trailingComma && properties.isNotEmpty) {
    stringBuffer.write(',');
  }

  stringBuffer.write(')');
  return stringBuffer.toString();
}