import 'package:flutter_ast_core/flutter_ast_core.dart'; import 'analyzer.dart'; import 'index.dart'; extension AstNodeUtils on AstNode { DartFile toDartFile([String path]) { DartFile base = DartFile(path: path); final List imports = []; for (final node in root.childEntities.whereType()) { final ImportDirectiveImpl _node = node; final _url = _node.uri.stringValue; imports.add(_url); } base = base.copyWith(imports: imports); final List fields = []; for (final node in root.childEntities.whereType()) { fields.add(node.toDartField()); } base = base.copyWith(fields: fields); final List methods = []; for (final node in root.childEntities.whereType()) { methods.add(node.toDartMethod()); } base = base.copyWith(methods: methods); final List classes = []; for (final node in root.childEntities.whereType()) { final ClassDeclarationImpl _node = node; classes.add(_node.toDartClass(base)); } base = base.copyWith(classes: classes); final List enums = []; for (final node in root.childEntities.whereType()) { final EnumDeclarationImpl _node = node; enums.add(_node.toDartEnum()); } base = base.copyWith(enums: enums); return base; } } extension DartFileUtils on DartFile { String toDart() { final sb = StringBuffer(); // TODO: Write back out to Dart return sb.toString(); } }