build method

  1. @override
String build()
override

Implementation

@override
String build() {
  final sb = StringBuffer();
  sb.write('[');
  sb.write(instanceName);
  sb.write(' ');
  sb.write(functionName);
  if (params.isNotEmpty) {
    sb.write(':');
    sb.write(params[0].value);
  }

  var signature =
      OneLine(depth: depth, body: sb.toString(), hasNewline: false);

  final ret = <CodeUnit>[];

  if (params.length > 1) {
    for (var i = 1; i < params.length; i++) {
      // 普通参数
      if (!params[i].value.contains('^')) {
        signature =
            LineExpand(signature, ' ${params[i].name}:${params[i].value}')
              ..hasNewline = false;
      } else {
        // Block 单独一行
        if (!signature.build().endsWith('\n')) {
          ret.add(EmptyLine());
        }
        ret.add(OneLine(
            depth: depth,
            body: '${params[i].name}:${params[i].value}',
            hasNewline: false));
      }
    }
  }
  ret.add(OneLine(depth: ignoreError == false ? depth : 0, body: '];'));

  ret.insert(0, signature);
  return CodeUnit.join(ret);
}