build method

  1. @override
String build()
override

Implementation

@override
String build() {
  // 只有接口才能生成方法
  if (methods.isNotEmpty) {
    assert(isInterface);
  }

  return CodeUnit.join([
    classSignature(),
    if (publicFields.isNotEmpty) ...javaPublicFields(),
    if (privateFields.isNotEmpty) ...javaPrivateFields(),
    if (privateFields.isNotEmpty || privateFields.isNotEmpty) EmptyLine(),
    if (fieldGettersAndSetters.isNotEmpty) ...getterAndSetters(),
    if (fieldGettersAndSetters.isNotEmpty)
      EmptyLine(), // 提供一个新的插入空行的美化方法,几个 List 以分组形式传入,在里面插 EmptyLine 再返回一个新扁平 List
    if (hasToMap) toMapFunc(),
    if (hasToMap) EmptyLine(),
    if (hasFromMap) fromMapFunc(),
    if (injectedJavaCodes != null) EmptyLine(),
    if (injectedJavaCodes != null) ...injectedJavaCodes!(depth + 1),
    if (methods.isNotEmpty) ...methodsInterfaces(),
    OneLine(depth: depth, body: '}')
  ]);
}