explainModel static method

String explainModel({
  1. required Lib lib,
  2. required SharedOptions options,
  3. required String content,
  4. required void callback(
    1. AssetItem asset
    ),
})

Implementation

static String explainModel({
  required Lib lib,
  required SharedOptions options,
  required String content,
  required void Function(AssetItem asset) callback
}) {
  // 解析AssetItem参数
  final String reArg = '[\\n\\s\'"]*([^\\s\\,\'"]+)[\\s\'"]*,?';
  // 解析AssetItem备注
  final String reMark = '[\\n\\s]*\\/\\*\\s*([^\\s]+)\\s+(Y|N)\\s*\\*\\/';
  // 解析AssetItem数据
  final String reAssetItem = '$reMark[\\n\\s]+static\\s+const\\s+$className\\s+([\\w\\d]+)\\s+\\=\\s+$className\\($reArg[\\n\\s]*\\);';
  return content.replaceAllMapped(RegExp(reAssetItem), (Match match) {
    final String hash = match.group(1)!;
    final String name = match.group(3)!;
    final String path = match.group(4)!;
    callback(
      AssetItem(
        path: path,
        name: name,
        hash: hash,
        lib: lib,
        options: options,
      ),
    );
    return '';
  });
}