diff --git a/.gitignore b/.gitignore index dbef116..f52fa55 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ # See https://www.dartlang.org/guides/libraries/private-files +*.exe # Files and directories created by pub .dart_tool/ diff --git a/example/dj_example.dart b/example/dj_example.dart index f9aab0a..17af644 100644 --- a/example/dj_example.dart +++ b/example/dj_example.dart @@ -15,13 +15,13 @@ void main() { // Adding this line for demonstration only! ImportDj(importStr: 'package:io/io.dart'), FunctionDj( - description: 'Main entry point to this file!', + descriptionDj: 'Main entry point to this file!', outputType: VariableType.Void, name: 'main', bodyCodeParts: [ FunctionCallDj( name: 'print', - args: ["'Hellow World!'"], + args: ["'Hello World!'"], ), ], ), diff --git a/lib/main/djs/code_djs/base_widget_dj.dart b/lib/main/djs/code_djs/base_widget_dj.dart new file mode 100644 index 0000000..15916ae --- /dev/null +++ b/lib/main/djs/code_djs/base_widget_dj.dart @@ -0,0 +1,29 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:dj/main/main.dart'; + +part 'base_widget_dj.g.dart'; + +@JsonSerializable() +class BaseWidgetDj extends CodePartDj { + @JsonKey(name: 'baseWidgetDjType') + final String baseWidgetDjType; + + BaseWidgetDj({ + required this.baseWidgetDjType, + descriptionDj, + CodePartDjType codePartDjType = CodePartDjType.BaseWidget, + }) : super( + descriptionDj: descriptionDj, + codePartDjType: codePartDjType, + ); + + factory BaseWidgetDj.fromJson(Map json) => + _$BaseWidgetDjFromJson(json); + @override + Map toJson() => _$BaseWidgetDjToJson(this); + + @override + List toCode() { + return super.toCode(); + } +} diff --git a/lib/main/djs/code_djs/base_widget_dj.g.dart b/lib/main/djs/code_djs/base_widget_dj.g.dart new file mode 100644 index 0000000..2c3d1ca --- /dev/null +++ b/lib/main/djs/code_djs/base_widget_dj.g.dart @@ -0,0 +1,76 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'base_widget_dj.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +BaseWidgetDj _$BaseWidgetDjFromJson(Map json) { + return BaseWidgetDj( + baseWidgetDjType: json['baseWidgetDjType'] as String, + descriptionDj: json['descriptionDj'], + codePartDjType: + _$enumDecode(_$CodePartDjTypeEnumMap, json['codePartDjType']), + ); +} + +Map _$BaseWidgetDjToJson(BaseWidgetDj instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('descriptionDj', instance.descriptionDj); + writeNotNull( + 'codePartDjType', _$CodePartDjTypeEnumMap[instance.codePartDjType]); + val['baseWidgetDjType'] = instance.baseWidgetDjType; + return val; +} + +K _$enumDecode( + Map enumValues, + Object? source, { + K? unknownValue, +}) { + if (source == null) { + throw ArgumentError( + 'A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}', + ); + } + + return enumValues.entries.singleWhere( + (e) => e.value == source, + orElse: () { + if (unknownValue == null) { + throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}', + ); + } + return MapEntry(unknownValue, enumValues.values.first); + }, + ).key; +} + +const _$CodePartDjTypeEnumMap = { + CodePartDjType.FunctionCall: 'FunctionCall', + CodePartDjType.Function: 'Function', + CodePartDjType.IfElse: 'IfElse', + CodePartDjType.Import: 'Import', + CodePartDjType.StatelessWidget: 'StatelessWidget', + CodePartDjType.Return: 'Return', + CodePartDjType.Class: 'Class', + CodePartDjType.Field: 'Field', + CodePartDjType.Enum: 'Enum', + CodePartDjType.Map: 'Map', + CodePartDjType.EmptyLine: 'EmptyLine', + CodePartDjType.VariableDeclaration: 'VariableDeclaration', + CodePartDjType.SingleLine: 'SingleLine', + CodePartDjType.Export: 'Export', + CodePartDjType.BaseWidget: 'BaseWidget', +}; diff --git a/lib/main/djs/code_djs/class.dart b/lib/main/djs/code_djs/class.dart new file mode 100644 index 0000000..cf7d739 --- /dev/null +++ b/lib/main/djs/code_djs/class.dart @@ -0,0 +1,154 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:dj/main/main.dart'; + +part 'class.g.dart'; + +@JsonSerializable() +class ClassDj extends CodePartDj { + @JsonKey(name: 'name') + final String? name; + + @JsonKey(name: 'baseName') + final String? baseName; + + @JsonKey(name: 'fields') + final List? fields; + + @JsonKey(name: 'isExtends') + final bool? isExtends; + + @JsonKey(name: 'isImplements') + final bool? isImplements; + + @JsonKey(name: 'jsonSerializable') + final bool? jsonSerializable; + + @JsonKey(name: 'functions') + final List? functions; + + ClassDj({ + descriptionDj, + this.name, + this.baseName, + this.fields, + this.isExtends, + this.isImplements, + this.jsonSerializable, + this.functions, + CodePartDjType codePartDjType = CodePartDjType.Class, + }) : super( + descriptionDj: descriptionDj, + codePartDjType: codePartDjType, + ); + + factory ClassDj.fromJson(Map json) => + _$ClassDjFromJson(json); + @override + Map toJson() => _$ClassDjToJson(this); + + List _constructorCode() { + var codeLines = []; + + codeLines.add('$name({'); + + var superOnlyFields = []; + + fields?.forEach((field) { + String? comment; + var fieldLine = '${field.name}'; + if (field.superOnly ?? false) { + superOnlyFields.add(field); + if (field.defaultValue != null) { + fieldLine = '$fieldLine = ${field.defaultValue}'; + } else { + fieldLine = '$fieldLine'; + } + } else if (field.hasDefaultValue) { + comment = 'ignoring defaultValue ${field.defaultValue}'; + fieldLine = 'this.$fieldLine'; + } else { + fieldLine = 'this.$fieldLine'; + if ((field.isRequired ?? false) && + (field.appliedDataType != 'dynamic')) { + fieldLine = 'required $fieldLine'; + } + } + fieldLine += ','; + if (comment != null) { + fieldLine += ' // $comment'; + } + if (!field.isPrivate) { + codeLines.add(fieldLine); + } + }); + + if (superOnlyFields.isEmpty) { + codeLines.add('});'); + } else { + codeLines.add('}) : super('); + superOnlyFields.forEach((field) { + codeLines.add('${field.name}:${field.name},'); + }); + codeLines.add(');'); + } + + if (functions != null) { + codeLines.add('\n'); + functions?.forEach((function) { + codeLines += function.toCode(); + }); + } + + return codeLines; + } + + @override + List toCode() { + var _lines = super.toCode(); + + var _jsonSerializable = jsonSerializable ?? false; + + if (name == null) return _lines; + + var baseLine = ''; + if ((isExtends ?? false) && (baseName ?? '').isNotEmpty) { + baseLine = 'extends $baseName'; + } + var classStartLine = [ + if (_jsonSerializable) '@JsonSerializable()', + 'class $name $baseLine {' + ]; + _lines += classStartLine; + + fields + ?.where((field) => (!(field.superOnly ?? false) && !field.isPrivate)) + .forEach((field) { + if (_jsonSerializable) { + _lines.add("@JsonKey(name: '${field.name}')"); + } + _lines += field.toCode(); + _lines.add(''); + }); + + _lines = _lines + _constructorCode(); + + if (jsonSerializable ?? false) { + _lines.add(''); + var jsFromLine1 = '$name.fromJson(Map json)'; + var jsFromLine2 = '_\$${name}FromJson(json);'; + var jsFromLine = 'factory $jsFromLine1 => $jsFromLine2'; + _lines.add(jsFromLine); + } + + if (jsonSerializable ?? false) { + _lines.add(''); + _lines.add('@override'); + _lines.add('Map toJson() => _\$${name}ToJson(this);'); + } + + // class end line + _lines.add('}'); + + return _lines; + } +} diff --git a/lib/main/djs/code_djs/class.g.dart b/lib/main/djs/code_djs/class.g.dart new file mode 100644 index 0000000..2e1b149 --- /dev/null +++ b/lib/main/djs/code_djs/class.g.dart @@ -0,0 +1,93 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'class.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +ClassDj _$ClassDjFromJson(Map json) { + return ClassDj( + descriptionDj: json['descriptionDj'], + name: json['name'] as String?, + baseName: json['baseName'] as String?, + fields: (json['fields'] as List?) + ?.map((e) => FieldDj.fromJson(e as Map)) + .toList(), + isExtends: json['isExtends'] as bool?, + isImplements: json['isImplements'] as bool?, + jsonSerializable: json['jsonSerializable'] as bool?, + functions: (json['functions'] as List?) + ?.map((e) => CodePartDj.fromJson(e as Map)) + .toList(), + codePartDjType: + _$enumDecode(_$CodePartDjTypeEnumMap, json['codePartDjType']), + ); +} + +Map _$ClassDjToJson(ClassDj instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('descriptionDj', instance.descriptionDj); + writeNotNull( + 'codePartDjType', _$CodePartDjTypeEnumMap[instance.codePartDjType]); + writeNotNull('name', instance.name); + writeNotNull('baseName', instance.baseName); + writeNotNull('fields', instance.fields?.map((e) => e.toJson()).toList()); + writeNotNull('isExtends', instance.isExtends); + writeNotNull('isImplements', instance.isImplements); + writeNotNull('jsonSerializable', instance.jsonSerializable); + writeNotNull( + 'functions', instance.functions?.map((e) => e.toJson()).toList()); + return val; +} + +K _$enumDecode( + Map enumValues, + Object? source, { + K? unknownValue, +}) { + if (source == null) { + throw ArgumentError( + 'A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}', + ); + } + + return enumValues.entries.singleWhere( + (e) => e.value == source, + orElse: () { + if (unknownValue == null) { + throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}', + ); + } + return MapEntry(unknownValue, enumValues.values.first); + }, + ).key; +} + +const _$CodePartDjTypeEnumMap = { + CodePartDjType.FunctionCall: 'FunctionCall', + CodePartDjType.Function: 'Function', + CodePartDjType.IfElse: 'IfElse', + CodePartDjType.Import: 'Import', + CodePartDjType.StatelessWidget: 'StatelessWidget', + CodePartDjType.Return: 'Return', + CodePartDjType.Class: 'Class', + CodePartDjType.Field: 'Field', + CodePartDjType.Enum: 'Enum', + CodePartDjType.Map: 'Map', + CodePartDjType.EmptyLine: 'EmptyLine', + CodePartDjType.VariableDeclaration: 'VariableDeclaration', + CodePartDjType.SingleLine: 'SingleLine', + CodePartDjType.Export: 'Export', + CodePartDjType.BaseWidget: 'BaseWidget', +}; diff --git a/lib/main/djs/code_djs/code_djs.dart b/lib/main/djs/code_djs/code_djs.dart index 98aea96..05356d5 100644 --- a/lib/main/djs/code_djs/code_djs.dart +++ b/lib/main/djs/code_djs/code_djs.dart @@ -3,5 +3,14 @@ export 'import.dart'; export 'function_call.dart'; export 'function.dart'; export 'if_else.dart'; -export 'stateless_widget.dart'; export 'return.dart'; +export 'field.dart'; +export 'class.dart'; +export 'enum.dart'; +export 'map.dart'; +export 'empty_line.dart'; +export 'variable_declaration.dart'; +export 'single_line.dart'; +export 'export.dart'; +export 'base_widget_dj.dart'; +export 'manual_widget_dj.dart'; diff --git a/lib/main/djs/code_djs/code_part.dart b/lib/main/djs/code_djs/code_part.dart index c9e5220..a515ad3 100644 --- a/lib/main/djs/code_djs/code_part.dart +++ b/lib/main/djs/code_djs/code_part.dart @@ -3,62 +3,89 @@ import 'package:dj/main/main.dart'; part 'code_part.g.dart'; -enum CodePartType { +enum CodePartDjType { FunctionCall, Function, IfElse, Import, StatelessWidget, Return, + Class, + Field, + Enum, + Map, + EmptyLine, + VariableDeclaration, + SingleLine, + Export, + BaseWidget, + // While adding New type here, don't forget to update CodePartDj.fromJson } @JsonSerializable() class CodePartDj { - @JsonKey(name: 'description') - final String? description; + @JsonKey(name: 'descriptionDj') + final String? descriptionDj; - @JsonKey(name: 'type') - final CodePartType? type; + @JsonKey(name: 'codePartDjType') + final CodePartDjType? codePartDjType; const CodePartDj({ - this.description, - this.type, + this.descriptionDj, + this.codePartDjType, }); factory CodePartDj.fromJson(Map json) { var codePartDj = _$CodePartDjFromJson(json); - switch (codePartDj.type) { - case CodePartType.Function: + switch (codePartDj.codePartDjType) { + case CodePartDjType.Function: return FunctionDj.fromJson(json); - case CodePartType.FunctionCall: + case CodePartDjType.FunctionCall: return FunctionCallDj.fromJson(json); - case CodePartType.IfElse: + case CodePartDjType.IfElse: return IfElseDj.fromJson(json); - case CodePartType.Import: + case CodePartDjType.Import: return ImportDj.fromJson(json); - case CodePartType.StatelessWidget: - return StatelessWidgetDj.fromJson(json); - case CodePartType.Return: + case CodePartDjType.Return: return ReturnDj.fromJson(json); + case CodePartDjType.Class: + return ClassDj.fromJson(json); + case CodePartDjType.Field: + return FieldDj.fromJson(json); + case CodePartDjType.Enum: + return EnumDj.fromJson(json); + case CodePartDjType.Map: + return MapDj.fromJson(json); + case CodePartDjType.EmptyLine: + return EmptyLineDj.fromJson(json); + case CodePartDjType.VariableDeclaration: + return VariableDeclarationDj.fromJson(json); + case CodePartDjType.SingleLine: + return SingleLineDj.fromJson(json); + case CodePartDjType.Export: + return ExportDj.fromJson(json); + case CodePartDjType.BaseWidget: + return BaseWidgetDj.fromJson(json); default: throw Exception( - 'CodePartDj.fromJson not handled for ${codePartDj.type}'); + 'CodePartDj.fromJson not handled for ${codePartDj.codePartDjType}', + ); } } Map toJson() => _$CodePartDjToJson(this); - List lines() { + List toCode() { var _lines = []; - _lines += getSingleLineCommectOnMultipleLines(description); + _lines += getSingleLineCommentOnMultipleLines(descriptionDj); return _lines; } @override String toString() { - return lines().join(' '); + return toCode().join(' '); } } diff --git a/lib/main/djs/code_djs/code_part.g.dart b/lib/main/djs/code_djs/code_part.g.dart index 9241e14..cf1eb20 100644 --- a/lib/main/djs/code_djs/code_part.g.dart +++ b/lib/main/djs/code_djs/code_part.g.dart @@ -8,8 +8,9 @@ part of 'code_part.dart'; CodePartDj _$CodePartDjFromJson(Map json) { return CodePartDj( - description: json['description'] as String?, - type: _$enumDecodeNullable(_$CodePartTypeEnumMap, json['type']), + descriptionDj: json['descriptionDj'] as String?, + codePartDjType: + _$enumDecodeNullable(_$CodePartDjTypeEnumMap, json['codePartDjType']), ); } @@ -22,8 +23,9 @@ Map _$CodePartDjToJson(CodePartDj instance) { } } - writeNotNull('description', instance.description); - writeNotNull('type', _$CodePartTypeEnumMap[instance.type]); + writeNotNull('descriptionDj', instance.descriptionDj); + writeNotNull( + 'codePartDjType', _$CodePartDjTypeEnumMap[instance.codePartDjType]); return val; } @@ -64,11 +66,20 @@ K? _$enumDecodeNullable( return _$enumDecode(enumValues, source, unknownValue: unknownValue); } -const _$CodePartTypeEnumMap = { - CodePartType.FunctionCall: 'FunctionCall', - CodePartType.Function: 'Function', - CodePartType.IfElse: 'IfElse', - CodePartType.Import: 'Import', - CodePartType.StatelessWidget: 'StatelessWidget', - CodePartType.Return: 'Return', +const _$CodePartDjTypeEnumMap = { + CodePartDjType.FunctionCall: 'FunctionCall', + CodePartDjType.Function: 'Function', + CodePartDjType.IfElse: 'IfElse', + CodePartDjType.Import: 'Import', + CodePartDjType.StatelessWidget: 'StatelessWidget', + CodePartDjType.Return: 'Return', + CodePartDjType.Class: 'Class', + CodePartDjType.Field: 'Field', + CodePartDjType.Enum: 'Enum', + CodePartDjType.Map: 'Map', + CodePartDjType.EmptyLine: 'EmptyLine', + CodePartDjType.VariableDeclaration: 'VariableDeclaration', + CodePartDjType.SingleLine: 'SingleLine', + CodePartDjType.Export: 'Export', + CodePartDjType.BaseWidget: 'BaseWidget', }; diff --git a/lib/main/djs/code_djs/empty_line.dart b/lib/main/djs/code_djs/empty_line.dart new file mode 100644 index 0000000..a8a93a1 --- /dev/null +++ b/lib/main/djs/code_djs/empty_line.dart @@ -0,0 +1,29 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:dj/main/main.dart'; + +part 'empty_line.g.dart'; + +@JsonSerializable() +class EmptyLineDj extends CodePartDj { + EmptyLineDj({ + descriptionDj, + CodePartDjType codePartDjType = CodePartDjType.EmptyLine, + }) : super( + descriptionDj: descriptionDj, + codePartDjType: codePartDjType, + ); + + factory EmptyLineDj.fromJson(Map json) => + _$EmptyLineDjFromJson(json); + @override + Map toJson() => _$EmptyLineDjToJson(this); + + @override + List toCode() { + var _lines = super.toCode(); + + _lines.add(''); + + return _lines; + } +} diff --git a/lib/main/djs/code_djs/empty_line.g.dart b/lib/main/djs/code_djs/empty_line.g.dart new file mode 100644 index 0000000..5e07ab0 --- /dev/null +++ b/lib/main/djs/code_djs/empty_line.g.dart @@ -0,0 +1,74 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'empty_line.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +EmptyLineDj _$EmptyLineDjFromJson(Map json) { + return EmptyLineDj( + descriptionDj: json['descriptionDj'], + codePartDjType: + _$enumDecode(_$CodePartDjTypeEnumMap, json['codePartDjType']), + ); +} + +Map _$EmptyLineDjToJson(EmptyLineDj instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('descriptionDj', instance.descriptionDj); + writeNotNull( + 'codePartDjType', _$CodePartDjTypeEnumMap[instance.codePartDjType]); + return val; +} + +K _$enumDecode( + Map enumValues, + Object? source, { + K? unknownValue, +}) { + if (source == null) { + throw ArgumentError( + 'A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}', + ); + } + + return enumValues.entries.singleWhere( + (e) => e.value == source, + orElse: () { + if (unknownValue == null) { + throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}', + ); + } + return MapEntry(unknownValue, enumValues.values.first); + }, + ).key; +} + +const _$CodePartDjTypeEnumMap = { + CodePartDjType.FunctionCall: 'FunctionCall', + CodePartDjType.Function: 'Function', + CodePartDjType.IfElse: 'IfElse', + CodePartDjType.Import: 'Import', + CodePartDjType.StatelessWidget: 'StatelessWidget', + CodePartDjType.Return: 'Return', + CodePartDjType.Class: 'Class', + CodePartDjType.Field: 'Field', + CodePartDjType.Enum: 'Enum', + CodePartDjType.Map: 'Map', + CodePartDjType.EmptyLine: 'EmptyLine', + CodePartDjType.VariableDeclaration: 'VariableDeclaration', + CodePartDjType.SingleLine: 'SingleLine', + CodePartDjType.Export: 'Export', + CodePartDjType.BaseWidget: 'BaseWidget', +}; diff --git a/lib/main/djs/code_djs/enum.dart b/lib/main/djs/code_djs/enum.dart new file mode 100644 index 0000000..66cb833 --- /dev/null +++ b/lib/main/djs/code_djs/enum.dart @@ -0,0 +1,42 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:dj/main/main.dart'; + +part 'enum.g.dart'; + +@JsonSerializable() +class EnumDj extends CodePartDj { + @JsonKey(name: 'name') + final String? name; + + @JsonKey(name: 'values') + final List? values; + + EnumDj({ + descriptionDj, + this.name, + this.values, + CodePartDjType codePartDjType = CodePartDjType.Enum, + }) : super( + descriptionDj: descriptionDj, + codePartDjType: codePartDjType, + ); + + factory EnumDj.fromJson(Map json) => _$EnumDjFromJson(json); + @override + Map toJson() => _$EnumDjToJson(this); + + @override + List toCode() { + var _lines = super.toCode(); + + _lines.add('enum $name {'); + + values?.forEach((value) { + _lines.add('$value,'); + }); + + _lines.add('}'); + + return _lines; + } +} diff --git a/lib/main/djs/code_djs/enum.g.dart b/lib/main/djs/code_djs/enum.g.dart new file mode 100644 index 0000000..a7d36f7 --- /dev/null +++ b/lib/main/djs/code_djs/enum.g.dart @@ -0,0 +1,79 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'enum.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +EnumDj _$EnumDjFromJson(Map json) { + return EnumDj( + descriptionDj: json['descriptionDj'], + name: json['name'] as String?, + values: + (json['values'] as List?)?.map((e) => e as String).toList(), + codePartDjType: + _$enumDecode(_$CodePartDjTypeEnumMap, json['codePartDjType']), + ); +} + +Map _$EnumDjToJson(EnumDj instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('descriptionDj', instance.descriptionDj); + writeNotNull( + 'codePartDjType', _$CodePartDjTypeEnumMap[instance.codePartDjType]); + writeNotNull('name', instance.name); + writeNotNull('values', instance.values); + return val; +} + +K _$enumDecode( + Map enumValues, + Object? source, { + K? unknownValue, +}) { + if (source == null) { + throw ArgumentError( + 'A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}', + ); + } + + return enumValues.entries.singleWhere( + (e) => e.value == source, + orElse: () { + if (unknownValue == null) { + throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}', + ); + } + return MapEntry(unknownValue, enumValues.values.first); + }, + ).key; +} + +const _$CodePartDjTypeEnumMap = { + CodePartDjType.FunctionCall: 'FunctionCall', + CodePartDjType.Function: 'Function', + CodePartDjType.IfElse: 'IfElse', + CodePartDjType.Import: 'Import', + CodePartDjType.StatelessWidget: 'StatelessWidget', + CodePartDjType.Return: 'Return', + CodePartDjType.Class: 'Class', + CodePartDjType.Field: 'Field', + CodePartDjType.Enum: 'Enum', + CodePartDjType.Map: 'Map', + CodePartDjType.EmptyLine: 'EmptyLine', + CodePartDjType.VariableDeclaration: 'VariableDeclaration', + CodePartDjType.SingleLine: 'SingleLine', + CodePartDjType.Export: 'Export', + CodePartDjType.BaseWidget: 'BaseWidget', +}; diff --git a/lib/main/djs/code_djs/export.dart b/lib/main/djs/code_djs/export.dart new file mode 100644 index 0000000..17231b5 --- /dev/null +++ b/lib/main/djs/code_djs/export.dart @@ -0,0 +1,34 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'code_part.dart'; + +part 'export.g.dart'; + +@JsonSerializable() +class ExportDj extends CodePartDj { + @JsonKey(name: 'exportStr') + final String? exportStr; + + ExportDj({ + descriptionDj, + this.exportStr, + CodePartDjType codePartDjType = CodePartDjType.Export, + }) : super( + descriptionDj: descriptionDj, + codePartDjType: codePartDjType, + ); + + factory ExportDj.fromJson(Map json) => + _$ExportDjFromJson(json); + @override + Map toJson() => _$ExportDjToJson(this); + + @override + List toCode() { + var codeLines = super.toCode(); + + var exportLine = "export '$exportStr.dart';"; + + codeLines.add(exportLine); + return codeLines; + } +} diff --git a/lib/main/djs/code_djs/export.g.dart b/lib/main/djs/code_djs/export.g.dart new file mode 100644 index 0000000..118947b --- /dev/null +++ b/lib/main/djs/code_djs/export.g.dart @@ -0,0 +1,76 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'export.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +ExportDj _$ExportDjFromJson(Map json) { + return ExportDj( + descriptionDj: json['descriptionDj'], + exportStr: json['exportStr'] as String?, + codePartDjType: + _$enumDecode(_$CodePartDjTypeEnumMap, json['codePartDjType']), + ); +} + +Map _$ExportDjToJson(ExportDj instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('descriptionDj', instance.descriptionDj); + writeNotNull( + 'codePartDjType', _$CodePartDjTypeEnumMap[instance.codePartDjType]); + writeNotNull('exportStr', instance.exportStr); + return val; +} + +K _$enumDecode( + Map enumValues, + Object? source, { + K? unknownValue, +}) { + if (source == null) { + throw ArgumentError( + 'A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}', + ); + } + + return enumValues.entries.singleWhere( + (e) => e.value == source, + orElse: () { + if (unknownValue == null) { + throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}', + ); + } + return MapEntry(unknownValue, enumValues.values.first); + }, + ).key; +} + +const _$CodePartDjTypeEnumMap = { + CodePartDjType.FunctionCall: 'FunctionCall', + CodePartDjType.Function: 'Function', + CodePartDjType.IfElse: 'IfElse', + CodePartDjType.Import: 'Import', + CodePartDjType.StatelessWidget: 'StatelessWidget', + CodePartDjType.Return: 'Return', + CodePartDjType.Class: 'Class', + CodePartDjType.Field: 'Field', + CodePartDjType.Enum: 'Enum', + CodePartDjType.Map: 'Map', + CodePartDjType.EmptyLine: 'EmptyLine', + CodePartDjType.VariableDeclaration: 'VariableDeclaration', + CodePartDjType.SingleLine: 'SingleLine', + CodePartDjType.Export: 'Export', + CodePartDjType.BaseWidget: 'BaseWidget', +}; diff --git a/lib/main/djs/code_djs/field.dart b/lib/main/djs/code_djs/field.dart new file mode 100644 index 0000000..c6427ec --- /dev/null +++ b/lib/main/djs/code_djs/field.dart @@ -0,0 +1,101 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:dj/main/main.dart'; + +part 'field.g.dart'; + +@JsonSerializable() +class FieldDj extends CodePartDj { + @JsonKey(name: 'name') + final String? name; + + @JsonKey(name: 'dataType') + final String? dataType; + + @JsonKey(name: 'safeDataType') + final String? safeDataType; + + @JsonKey(name: 'safetyDescription') + final List? safetyDescription; + + @JsonKey(name: 'isFinal') + final bool? isFinal; + + @JsonKey(name: 'isRequired') + final bool? isRequired; + + @JsonKey(name: 'isOptional') + final bool? isOptional; + + @JsonKey(name: 'isStatic') + final bool? isStatic; + + @JsonKey(name: 'superOnly') + final bool? superOnly; + + @JsonKey(name: 'defaultValue') + final dynamic defaultValue; + + FieldDj({ + descriptionDj, + this.name, + this.dataType, + this.safeDataType, + this.safetyDescription, + this.isFinal = true, + this.isRequired = true, + this.isOptional = false, + this.superOnly = false, + this.isStatic = false, + this.defaultValue, + CodePartDjType codePartDjType = CodePartDjType.Field, + }) : super( + descriptionDj: descriptionDj, + codePartDjType: codePartDjType, + ); + + factory FieldDj.fromJson(Map json) => + _$FieldDjFromJson(json); + @override + Map toJson() => _$FieldDjToJson(this); + + @override + List toCode() { + var _lines = super.toCode(); + + if (name == null) return _lines; + + (safetyDescription ?? []).forEach((safetyDescriptionLine) { + _lines.add(safetyDescriptionLine); + }); + var dataTypeLine = appliedDataType; + + var fieldLine = '$dataTypeLine $name;'; + + if (isFinal ?? false) { + fieldLine = 'final $fieldLine'; + } + + _lines.add(fieldLine); + return _lines; + } + + // + // Getters + // + + String get appliedDataType { + late String dataTypeLine; + if (safeDataType != null) { + dataTypeLine = safeDataType!; + } else if (dataType != null) { + dataTypeLine = dataType!; + } else { + dataTypeLine = 'dynamic'; + } + return dataTypeLine; + } + + bool get hasDefaultValue => defaultValue != null; + + bool get isPrivate => (name ?? '').startsWith('_'); +} diff --git a/lib/main/djs/code_djs/field.g.dart b/lib/main/djs/code_djs/field.g.dart new file mode 100644 index 0000000..96dd503 --- /dev/null +++ b/lib/main/djs/code_djs/field.g.dart @@ -0,0 +1,96 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'field.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +FieldDj _$FieldDjFromJson(Map json) { + return FieldDj( + descriptionDj: json['descriptionDj'], + name: json['name'] as String?, + dataType: json['dataType'] as String?, + safeDataType: json['safeDataType'] as String?, + safetyDescription: (json['safetyDescription'] as List?) + ?.map((e) => e as String) + .toList(), + isFinal: json['isFinal'] as bool?, + isRequired: json['isRequired'] as bool?, + isOptional: json['isOptional'] as bool?, + superOnly: json['superOnly'] as bool?, + isStatic: json['isStatic'] as bool?, + defaultValue: json['defaultValue'], + codePartDjType: + _$enumDecode(_$CodePartDjTypeEnumMap, json['codePartDjType']), + ); +} + +Map _$FieldDjToJson(FieldDj instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('descriptionDj', instance.descriptionDj); + writeNotNull( + 'codePartDjType', _$CodePartDjTypeEnumMap[instance.codePartDjType]); + writeNotNull('name', instance.name); + writeNotNull('dataType', instance.dataType); + writeNotNull('safeDataType', instance.safeDataType); + writeNotNull('safetyDescription', instance.safetyDescription); + writeNotNull('isFinal', instance.isFinal); + writeNotNull('isRequired', instance.isRequired); + writeNotNull('isOptional', instance.isOptional); + writeNotNull('isStatic', instance.isStatic); + writeNotNull('superOnly', instance.superOnly); + writeNotNull('defaultValue', instance.defaultValue); + return val; +} + +K _$enumDecode( + Map enumValues, + Object? source, { + K? unknownValue, +}) { + if (source == null) { + throw ArgumentError( + 'A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}', + ); + } + + return enumValues.entries.singleWhere( + (e) => e.value == source, + orElse: () { + if (unknownValue == null) { + throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}', + ); + } + return MapEntry(unknownValue, enumValues.values.first); + }, + ).key; +} + +const _$CodePartDjTypeEnumMap = { + CodePartDjType.FunctionCall: 'FunctionCall', + CodePartDjType.Function: 'Function', + CodePartDjType.IfElse: 'IfElse', + CodePartDjType.Import: 'Import', + CodePartDjType.StatelessWidget: 'StatelessWidget', + CodePartDjType.Return: 'Return', + CodePartDjType.Class: 'Class', + CodePartDjType.Field: 'Field', + CodePartDjType.Enum: 'Enum', + CodePartDjType.Map: 'Map', + CodePartDjType.EmptyLine: 'EmptyLine', + CodePartDjType.VariableDeclaration: 'VariableDeclaration', + CodePartDjType.SingleLine: 'SingleLine', + CodePartDjType.Export: 'Export', + CodePartDjType.BaseWidget: 'BaseWidget', +}; diff --git a/lib/main/djs/code_djs/function.dart b/lib/main/djs/code_djs/function.dart index 1119e27..252aeb3 100644 --- a/lib/main/djs/code_djs/function.dart +++ b/lib/main/djs/code_djs/function.dart @@ -5,8 +5,8 @@ part 'function.g.dart'; @JsonSerializable() class FunctionDj extends CodePartDj { - @JsonKey(name: 'outputStr') - final VariableType outputType; + @JsonKey(name: 'outputType') + final VariableType? outputType; @JsonKey(name: 'name') final String name; @@ -20,17 +20,21 @@ class FunctionDj extends CodePartDj { @JsonKey(name: 'bodyCodeParts') final List? bodyCodeParts; + @JsonKey(name: 'annotations') + final List? annotations; + FunctionDj({ - description, - required this.outputType, + descriptionDj, + this.outputType, required this.name, this.args, this.isAsync = false, this.bodyCodeParts, - CodePartType type = CodePartType.Function, + this.annotations, + CodePartDjType codePartDjType = CodePartDjType.Function, }) : super( - description: description, - type: type, + descriptionDj: descriptionDj, + codePartDjType: codePartDjType, ); factory FunctionDj.fromJson(Map json) => @@ -39,12 +43,14 @@ class FunctionDj extends CodePartDj { Map toJson() => _$FunctionDjToJson(this); @override - List lines() { - var _lines = super.lines(); + List toCode() { + var _lines = super.toCode(); var argsLine = args?.map((arg) => '${arg.toString()}').join(', ') ?? ''; - var callLine = '$name($argsLine)'; + var callLine = ''; + + callLine += '$name($argsLine)'; if (isAsync) { callLine += ' async '; @@ -55,9 +61,17 @@ class FunctionDj extends CodePartDj { body += codePart.toString(); }); - var outputStr = variableTypeToString(outputType); + callLine = '$callLine { $body }'; - callLine = '$outputStr $callLine { $body }'; + if (outputType != null) { + callLine = variableTypeToString(outputType!) + ' ' + callLine; + } + + if (annotations != null) { + annotations!.forEach((annotation) { + callLine = '@$annotation\n' + callLine; + }); + } _lines.add(callLine); return _lines; diff --git a/lib/main/djs/code_djs/function.g.dart b/lib/main/djs/code_djs/function.g.dart index 851c808..851048d 100644 --- a/lib/main/djs/code_djs/function.g.dart +++ b/lib/main/djs/code_djs/function.g.dart @@ -8,8 +8,8 @@ part of 'function.dart'; FunctionDj _$FunctionDjFromJson(Map json) { return FunctionDj( - description: json['description'], - outputType: _$enumDecode(_$VariableTypeEnumMap, json['outputStr']), + descriptionDj: json['descriptionDj'], + outputType: _$enumDecodeNullable(_$VariableTypeEnumMap, json['outputType']), name: json['name'] as String, args: (json['args'] as List?) ?.map((e) => FunctionArg.fromJson(e as Map)) @@ -18,7 +18,11 @@ FunctionDj _$FunctionDjFromJson(Map json) { bodyCodeParts: (json['bodyCodeParts'] as List?) ?.map((e) => CodePartDj.fromJson(e as Map)) .toList(), - type: _$enumDecode(_$CodePartTypeEnumMap, json['type']), + annotations: (json['annotations'] as List?) + ?.map((e) => e as String) + .toList(), + codePartDjType: + _$enumDecode(_$CodePartDjTypeEnumMap, json['codePartDjType']), ); } @@ -31,14 +35,16 @@ Map _$FunctionDjToJson(FunctionDj instance) { } } - writeNotNull('description', instance.description); - writeNotNull('type', _$CodePartTypeEnumMap[instance.type]); - val['outputStr'] = _$VariableTypeEnumMap[instance.outputType]; + writeNotNull('descriptionDj', instance.descriptionDj); + writeNotNull( + 'codePartDjType', _$CodePartDjTypeEnumMap[instance.codePartDjType]); + writeNotNull('outputType', _$VariableTypeEnumMap[instance.outputType]); val['name'] = instance.name; writeNotNull('args', instance.args?.map((e) => e.toJson()).toList()); val['isAsync'] = instance.isAsync; writeNotNull( 'bodyCodeParts', instance.bodyCodeParts?.map((e) => e.toJson()).toList()); + writeNotNull('annotations', instance.annotations); return val; } @@ -68,17 +74,40 @@ K _$enumDecode( ).key; } +K? _$enumDecodeNullable( + Map enumValues, + dynamic source, { + K? unknownValue, +}) { + if (source == null) { + return null; + } + return _$enumDecode(enumValues, source, unknownValue: unknownValue); +} + const _$VariableTypeEnumMap = { VariableType.Void: 'Void', VariableType.String: 'String', VariableType.StringNullable: 'StringNullable', + VariableType.ListString: 'ListString', + VariableType.ListStringNullable: 'ListStringNullable', + VariableType.Var: 'Var', }; -const _$CodePartTypeEnumMap = { - CodePartType.FunctionCall: 'FunctionCall', - CodePartType.Function: 'Function', - CodePartType.IfElse: 'IfElse', - CodePartType.Import: 'Import', - CodePartType.StatelessWidget: 'StatelessWidget', - CodePartType.Return: 'Return', +const _$CodePartDjTypeEnumMap = { + CodePartDjType.FunctionCall: 'FunctionCall', + CodePartDjType.Function: 'Function', + CodePartDjType.IfElse: 'IfElse', + CodePartDjType.Import: 'Import', + CodePartDjType.StatelessWidget: 'StatelessWidget', + CodePartDjType.Return: 'Return', + CodePartDjType.Class: 'Class', + CodePartDjType.Field: 'Field', + CodePartDjType.Enum: 'Enum', + CodePartDjType.Map: 'Map', + CodePartDjType.EmptyLine: 'EmptyLine', + CodePartDjType.VariableDeclaration: 'VariableDeclaration', + CodePartDjType.SingleLine: 'SingleLine', + CodePartDjType.Export: 'Export', + CodePartDjType.BaseWidget: 'BaseWidget', }; diff --git a/lib/main/djs/code_djs/function_call.dart b/lib/main/djs/code_djs/function_call.dart index ecc90c9..409251e 100644 --- a/lib/main/djs/code_djs/function_call.dart +++ b/lib/main/djs/code_djs/function_call.dart @@ -18,15 +18,15 @@ class FunctionCallDj extends CodePartDj { final List? args; FunctionCallDj({ - description, + descriptionDj, this.outputStr, required this.name, this.arg, this.args, - CodePartType type = CodePartType.FunctionCall, + CodePartDjType codePartDjType = CodePartDjType.FunctionCall, }) : super( - description: description, - type: type, + descriptionDj: descriptionDj, + codePartDjType: codePartDjType, ); factory FunctionCallDj.fromJson(Map json) => @@ -35,8 +35,8 @@ class FunctionCallDj extends CodePartDj { Map toJson() => _$FunctionCallDjToJson(this); @override - List lines() { - var _lines = super.lines(); + List toCode() { + var _lines = super.toCode(); var argsLine = arg == null ? args?.map((arg) => '${arg.toString()}').join(', ') ?? '' diff --git a/lib/main/djs/code_djs/function_call.g.dart b/lib/main/djs/code_djs/function_call.g.dart index bded893..de97b19 100644 --- a/lib/main/djs/code_djs/function_call.g.dart +++ b/lib/main/djs/code_djs/function_call.g.dart @@ -8,12 +8,13 @@ part of 'function_call.dart'; FunctionCallDj _$FunctionCallDjFromJson(Map json) { return FunctionCallDj( - description: json['description'], + descriptionDj: json['descriptionDj'], outputStr: json['outputStr'] as String?, name: json['name'] as String, arg: json['arg'] as String?, args: (json['args'] as List?)?.map((e) => e as String).toList(), - type: _$enumDecode(_$CodePartTypeEnumMap, json['type']), + codePartDjType: + _$enumDecode(_$CodePartDjTypeEnumMap, json['codePartDjType']), ); } @@ -26,8 +27,9 @@ Map _$FunctionCallDjToJson(FunctionCallDj instance) { } } - writeNotNull('description', instance.description); - writeNotNull('type', _$CodePartTypeEnumMap[instance.type]); + writeNotNull('descriptionDj', instance.descriptionDj); + writeNotNull( + 'codePartDjType', _$CodePartDjTypeEnumMap[instance.codePartDjType]); writeNotNull('outputStr', instance.outputStr); val['name'] = instance.name; writeNotNull('arg', instance.arg); @@ -61,11 +63,20 @@ K _$enumDecode( ).key; } -const _$CodePartTypeEnumMap = { - CodePartType.FunctionCall: 'FunctionCall', - CodePartType.Function: 'Function', - CodePartType.IfElse: 'IfElse', - CodePartType.Import: 'Import', - CodePartType.StatelessWidget: 'StatelessWidget', - CodePartType.Return: 'Return', +const _$CodePartDjTypeEnumMap = { + CodePartDjType.FunctionCall: 'FunctionCall', + CodePartDjType.Function: 'Function', + CodePartDjType.IfElse: 'IfElse', + CodePartDjType.Import: 'Import', + CodePartDjType.StatelessWidget: 'StatelessWidget', + CodePartDjType.Return: 'Return', + CodePartDjType.Class: 'Class', + CodePartDjType.Field: 'Field', + CodePartDjType.Enum: 'Enum', + CodePartDjType.Map: 'Map', + CodePartDjType.EmptyLine: 'EmptyLine', + CodePartDjType.VariableDeclaration: 'VariableDeclaration', + CodePartDjType.SingleLine: 'SingleLine', + CodePartDjType.Export: 'Export', + CodePartDjType.BaseWidget: 'BaseWidget', }; diff --git a/lib/main/djs/code_djs/if_else.dart b/lib/main/djs/code_djs/if_else.dart index 38c2c21..339c4ae 100644 --- a/lib/main/djs/code_djs/if_else.dart +++ b/lib/main/djs/code_djs/if_else.dart @@ -9,12 +9,12 @@ class IfElseDj extends CodePartDj { final List? conditions; IfElseDj({ - description, + descriptionDj, this.conditions, - CodePartType type = CodePartType.IfElse, + CodePartDjType codePartDjType = CodePartDjType.IfElse, }) : super( - description: description, - type: type, + descriptionDj: descriptionDj, + codePartDjType: codePartDjType, ); factory IfElseDj.fromJson(Map json) => @@ -23,8 +23,8 @@ class IfElseDj extends CodePartDj { Map toJson() => _$IfElseDjToJson(this); @override - List lines() { - var _lines = super.lines(); + List toCode() { + var _lines = super.toCode(); var i = 0; conditions?.forEach((condition) { diff --git a/lib/main/djs/code_djs/if_else.g.dart b/lib/main/djs/code_djs/if_else.g.dart index 51944cf..327c097 100644 --- a/lib/main/djs/code_djs/if_else.g.dart +++ b/lib/main/djs/code_djs/if_else.g.dart @@ -8,11 +8,12 @@ part of 'if_else.dart'; IfElseDj _$IfElseDjFromJson(Map json) { return IfElseDj( - description: json['description'], + descriptionDj: json['descriptionDj'], conditions: (json['conditions'] as List?) ?.map((e) => Condition.fromJson(e as Map)) .toList(), - type: _$enumDecode(_$CodePartTypeEnumMap, json['type']), + codePartDjType: + _$enumDecode(_$CodePartDjTypeEnumMap, json['codePartDjType']), ); } @@ -25,8 +26,9 @@ Map _$IfElseDjToJson(IfElseDj instance) { } } - writeNotNull('description', instance.description); - writeNotNull('type', _$CodePartTypeEnumMap[instance.type]); + writeNotNull('descriptionDj', instance.descriptionDj); + writeNotNull( + 'codePartDjType', _$CodePartDjTypeEnumMap[instance.codePartDjType]); writeNotNull( 'conditions', instance.conditions?.map((e) => e.toJson()).toList()); return val; @@ -58,11 +60,20 @@ K _$enumDecode( ).key; } -const _$CodePartTypeEnumMap = { - CodePartType.FunctionCall: 'FunctionCall', - CodePartType.Function: 'Function', - CodePartType.IfElse: 'IfElse', - CodePartType.Import: 'Import', - CodePartType.StatelessWidget: 'StatelessWidget', - CodePartType.Return: 'Return', +const _$CodePartDjTypeEnumMap = { + CodePartDjType.FunctionCall: 'FunctionCall', + CodePartDjType.Function: 'Function', + CodePartDjType.IfElse: 'IfElse', + CodePartDjType.Import: 'Import', + CodePartDjType.StatelessWidget: 'StatelessWidget', + CodePartDjType.Return: 'Return', + CodePartDjType.Class: 'Class', + CodePartDjType.Field: 'Field', + CodePartDjType.Enum: 'Enum', + CodePartDjType.Map: 'Map', + CodePartDjType.EmptyLine: 'EmptyLine', + CodePartDjType.VariableDeclaration: 'VariableDeclaration', + CodePartDjType.SingleLine: 'SingleLine', + CodePartDjType.Export: 'Export', + CodePartDjType.BaseWidget: 'BaseWidget', }; diff --git a/lib/main/djs/code_djs/import.dart b/lib/main/djs/code_djs/import.dart index 38ab625..c6c91aa 100644 --- a/lib/main/djs/code_djs/import.dart +++ b/lib/main/djs/code_djs/import.dart @@ -8,13 +8,29 @@ class ImportDj extends CodePartDj { @JsonKey(name: 'importStr') final String importStr; + @JsonKey(name: 'isPackage') + final bool isPackage; + + @JsonKey(name: 'isFlutter') + final bool isFlutter; + + @JsonKey(name: 'isFile') + final bool isFile; + + @JsonKey(name: 'isPart') + final bool isPart; + ImportDj({ - description, + descriptionDj, this.importStr = '', - CodePartType type = CodePartType.Import, + this.isPackage = false, + this.isFlutter = false, + this.isFile = false, + this.isPart = false, + CodePartDjType codePartDjType = CodePartDjType.Import, }) : super( - description: description, - type: type, + descriptionDj: descriptionDj, + codePartDjType: codePartDjType, ); factory ImportDj.fromJson(Map json) => @@ -23,10 +39,22 @@ class ImportDj extends CodePartDj { Map toJson() => _$ImportDjToJson(this); @override - List lines() { - var _lines = super.lines(); + List toCode() { + var _lines = super.toCode(); - var importLine = "import '$importStr';"; + var importLine = "import '"; + if (isPackage) { + importLine += 'package:$importStr/$importStr.dart'; + } else if (isFlutter) { + importLine += 'package:flutter/$importStr.dart'; + } else if (isPart) { + importLine = "part '$importStr.g.dart"; + } else if (isFile) { + importLine += '$importStr.dart'; + } else { + importLine += '$importStr'; + } + importLine += "';"; _lines.add(importLine); return _lines; diff --git a/lib/main/djs/code_djs/import.g.dart b/lib/main/djs/code_djs/import.g.dart index ff3d97b..50b4505 100644 --- a/lib/main/djs/code_djs/import.g.dart +++ b/lib/main/djs/code_djs/import.g.dart @@ -8,9 +8,14 @@ part of 'import.dart'; ImportDj _$ImportDjFromJson(Map json) { return ImportDj( - description: json['description'], + descriptionDj: json['descriptionDj'], importStr: json['importStr'] as String, - type: _$enumDecode(_$CodePartTypeEnumMap, json['type']), + isPackage: json['isPackage'] as bool, + isFlutter: json['isFlutter'] as bool, + isFile: json['isFile'] as bool, + isPart: json['isPart'] as bool, + codePartDjType: + _$enumDecode(_$CodePartDjTypeEnumMap, json['codePartDjType']), ); } @@ -23,9 +28,14 @@ Map _$ImportDjToJson(ImportDj instance) { } } - writeNotNull('description', instance.description); - writeNotNull('type', _$CodePartTypeEnumMap[instance.type]); + writeNotNull('descriptionDj', instance.descriptionDj); + writeNotNull( + 'codePartDjType', _$CodePartDjTypeEnumMap[instance.codePartDjType]); val['importStr'] = instance.importStr; + val['isPackage'] = instance.isPackage; + val['isFlutter'] = instance.isFlutter; + val['isFile'] = instance.isFile; + val['isPart'] = instance.isPart; return val; } @@ -55,11 +65,20 @@ K _$enumDecode( ).key; } -const _$CodePartTypeEnumMap = { - CodePartType.FunctionCall: 'FunctionCall', - CodePartType.Function: 'Function', - CodePartType.IfElse: 'IfElse', - CodePartType.Import: 'Import', - CodePartType.StatelessWidget: 'StatelessWidget', - CodePartType.Return: 'Return', +const _$CodePartDjTypeEnumMap = { + CodePartDjType.FunctionCall: 'FunctionCall', + CodePartDjType.Function: 'Function', + CodePartDjType.IfElse: 'IfElse', + CodePartDjType.Import: 'Import', + CodePartDjType.StatelessWidget: 'StatelessWidget', + CodePartDjType.Return: 'Return', + CodePartDjType.Class: 'Class', + CodePartDjType.Field: 'Field', + CodePartDjType.Enum: 'Enum', + CodePartDjType.Map: 'Map', + CodePartDjType.EmptyLine: 'EmptyLine', + CodePartDjType.VariableDeclaration: 'VariableDeclaration', + CodePartDjType.SingleLine: 'SingleLine', + CodePartDjType.Export: 'Export', + CodePartDjType.BaseWidget: 'BaseWidget', }; diff --git a/lib/main/djs/code_djs/manual_widget_dj.dart b/lib/main/djs/code_djs/manual_widget_dj.dart new file mode 100644 index 0000000..d063fb1 --- /dev/null +++ b/lib/main/djs/code_djs/manual_widget_dj.dart @@ -0,0 +1,79 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:dj/main/main.dart'; + +part 'manual_widget_dj.g.dart'; + +@JsonSerializable() +class ManualWidgetDj extends BaseWidgetDj { + @JsonKey(name: 'key') + dynamic key; + + @JsonKey(name: 'name') + String? name; + + @JsonKey(name: 'params') + List? params; + + @JsonKey(name: 'args') + Map? args; + + // Should the arg be ignored in toCode conversation if null or empty + @JsonKey(name: 'ignoreArgIfNot') + bool? ignoreArgIfNot; + + ManualWidgetDj({ + this.key, + this.name, + this.params, + this.args, + this.ignoreArgIfNot = true, + baseWidgetDjType = 'ManualWidget', + }) : super( + baseWidgetDjType: baseWidgetDjType, + ); + + bool get ignoreArgIfNotNN => ignoreArgIfNot ?? true; + + @override + List toCode() { + var codeLines = super.toCode(); + + if (name == null) { + return codeLines; + } + + codeLines.add('$name('); + + if (key != null) { + codeLines.add('key:$key,'); + } + + String? getValueString(value) { + switch (value.runtimeType) { + case Null: + if (!ignoreArgIfNotNN) { + return '$value'; + } + break; + case String: + return "'$value'"; + default: + return '$value'; + } + } + + params?.forEach((param) { + codeLines.add('${getValueString(param)},'); + }); + + args?.forEach((key, value) { + var valueString = getValueString(value); + if (valueString != null) { + codeLines.add('$key:$valueString,'); + } + }); + + codeLines.add(')'); + return codeLines; + } +} diff --git a/lib/main/djs/code_djs/manual_widget_dj.g.dart b/lib/main/djs/code_djs/manual_widget_dj.g.dart new file mode 100644 index 0000000..168ca5d --- /dev/null +++ b/lib/main/djs/code_djs/manual_widget_dj.g.dart @@ -0,0 +1,38 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'manual_widget_dj.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +ManualWidgetDj _$ManualWidgetDjFromJson(Map json) { + return ManualWidgetDj( + key: json['key'], + name: json['name'] as String?, + params: + (json['params'] as List?)?.map((e) => e as String).toList(), + args: json['args'] as Map?, + ignoreArgIfNot: json['ignoreArgIfNot'] as bool?, + baseWidgetDjType: json['baseWidgetDjType'], + ); +} + +Map _$ManualWidgetDjToJson(ManualWidgetDj instance) { + final val = { + 'baseWidgetDjType': instance.baseWidgetDjType, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('key', instance.key); + writeNotNull('name', instance.name); + writeNotNull('params', instance.params); + writeNotNull('args', instance.args); + writeNotNull('ignoreArgIfNot', instance.ignoreArgIfNot); + return val; +} diff --git a/lib/main/djs/code_djs/map.dart b/lib/main/djs/code_djs/map.dart new file mode 100644 index 0000000..385d19a --- /dev/null +++ b/lib/main/djs/code_djs/map.dart @@ -0,0 +1,55 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:dj/main/main.dart'; + +part 'map.g.dart'; + +@JsonSerializable() +class MapDj extends CodePartDj { + @JsonKey(name: 'name') + final String? name; + + @JsonKey(name: 'keyDataType') + final String? keyDataType; + + @JsonKey(name: 'valueDataType') + final String? valueDataType; + + @JsonKey(name: 'values') + final Map? values; + + MapDj({ + descriptionDj, + this.name, + this.keyDataType, + this.valueDataType, + this.values, + CodePartDjType codePartDjType = CodePartDjType.Map, + }) : super( + descriptionDj: descriptionDj, + codePartDjType: codePartDjType, + ); + + factory MapDj.fromJson(Map json) => _$MapDjFromJson(json); + @override + Map toJson() => _$MapDjToJson(this); + + @override + List toCode() { + var _lines = super.toCode(); + + if (name == null) return _lines; + + var _keyDataType = keyDataType ?? 'dynamic'; + var _valueDataType = valueDataType ?? 'dynamic'; + + _lines.add('var $name = <$_keyDataType,$_valueDataType>{'); + + values?.forEach((key, value) { + _lines.add("'$key':'$value',"); + }); + + _lines.add('};'); + + return _lines; + } +} diff --git a/lib/main/djs/code_djs/map.g.dart b/lib/main/djs/code_djs/map.g.dart new file mode 100644 index 0000000..a95355e --- /dev/null +++ b/lib/main/djs/code_djs/map.g.dart @@ -0,0 +1,84 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'map.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +MapDj _$MapDjFromJson(Map json) { + return MapDj( + descriptionDj: json['descriptionDj'], + name: json['name'] as String?, + keyDataType: json['keyDataType'] as String?, + valueDataType: json['valueDataType'] as String?, + values: (json['values'] as Map?)?.map( + (k, e) => MapEntry(k, e as String), + ), + codePartDjType: + _$enumDecode(_$CodePartDjTypeEnumMap, json['codePartDjType']), + ); +} + +Map _$MapDjToJson(MapDj instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('descriptionDj', instance.descriptionDj); + writeNotNull( + 'codePartDjType', _$CodePartDjTypeEnumMap[instance.codePartDjType]); + writeNotNull('name', instance.name); + writeNotNull('keyDataType', instance.keyDataType); + writeNotNull('valueDataType', instance.valueDataType); + writeNotNull('values', instance.values); + return val; +} + +K _$enumDecode( + Map enumValues, + Object? source, { + K? unknownValue, +}) { + if (source == null) { + throw ArgumentError( + 'A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}', + ); + } + + return enumValues.entries.singleWhere( + (e) => e.value == source, + orElse: () { + if (unknownValue == null) { + throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}', + ); + } + return MapEntry(unknownValue, enumValues.values.first); + }, + ).key; +} + +const _$CodePartDjTypeEnumMap = { + CodePartDjType.FunctionCall: 'FunctionCall', + CodePartDjType.Function: 'Function', + CodePartDjType.IfElse: 'IfElse', + CodePartDjType.Import: 'Import', + CodePartDjType.StatelessWidget: 'StatelessWidget', + CodePartDjType.Return: 'Return', + CodePartDjType.Class: 'Class', + CodePartDjType.Field: 'Field', + CodePartDjType.Enum: 'Enum', + CodePartDjType.Map: 'Map', + CodePartDjType.EmptyLine: 'EmptyLine', + CodePartDjType.VariableDeclaration: 'VariableDeclaration', + CodePartDjType.SingleLine: 'SingleLine', + CodePartDjType.Export: 'Export', + CodePartDjType.BaseWidget: 'BaseWidget', +}; diff --git a/lib/main/djs/code_djs/return.dart b/lib/main/djs/code_djs/return.dart index 9ca4f2e..595b2af 100644 --- a/lib/main/djs/code_djs/return.dart +++ b/lib/main/djs/code_djs/return.dart @@ -9,12 +9,12 @@ class ReturnDj extends CodePartDj { final String returnStr; ReturnDj({ - description, + descriptionDj, this.returnStr = '', - CodePartType type = CodePartType.Return, + CodePartDjType codePartDjType = CodePartDjType.Return, }) : super( - description: description, - type: type, + descriptionDj: descriptionDj, + codePartDjType: codePartDjType, ); factory ReturnDj.fromJson(Map json) => @@ -23,8 +23,8 @@ class ReturnDj extends CodePartDj { Map toJson() => _$ReturnDjToJson(this); @override - List lines() { - var _lines = super.lines(); + List toCode() { + var _lines = super.toCode(); var returnLine = 'return $returnStr;'; diff --git a/lib/main/djs/code_djs/return.g.dart b/lib/main/djs/code_djs/return.g.dart index 94201ff..854ed8c 100644 --- a/lib/main/djs/code_djs/return.g.dart +++ b/lib/main/djs/code_djs/return.g.dart @@ -8,9 +8,10 @@ part of 'return.dart'; ReturnDj _$ReturnDjFromJson(Map json) { return ReturnDj( - description: json['description'], + descriptionDj: json['descriptionDj'], returnStr: json['returnStr'] as String, - type: _$enumDecode(_$CodePartTypeEnumMap, json['type']), + codePartDjType: + _$enumDecode(_$CodePartDjTypeEnumMap, json['codePartDjType']), ); } @@ -23,8 +24,9 @@ Map _$ReturnDjToJson(ReturnDj instance) { } } - writeNotNull('description', instance.description); - writeNotNull('type', _$CodePartTypeEnumMap[instance.type]); + writeNotNull('descriptionDj', instance.descriptionDj); + writeNotNull( + 'codePartDjType', _$CodePartDjTypeEnumMap[instance.codePartDjType]); val['returnStr'] = instance.returnStr; return val; } @@ -55,11 +57,20 @@ K _$enumDecode( ).key; } -const _$CodePartTypeEnumMap = { - CodePartType.FunctionCall: 'FunctionCall', - CodePartType.Function: 'Function', - CodePartType.IfElse: 'IfElse', - CodePartType.Import: 'Import', - CodePartType.StatelessWidget: 'StatelessWidget', - CodePartType.Return: 'Return', +const _$CodePartDjTypeEnumMap = { + CodePartDjType.FunctionCall: 'FunctionCall', + CodePartDjType.Function: 'Function', + CodePartDjType.IfElse: 'IfElse', + CodePartDjType.Import: 'Import', + CodePartDjType.StatelessWidget: 'StatelessWidget', + CodePartDjType.Return: 'Return', + CodePartDjType.Class: 'Class', + CodePartDjType.Field: 'Field', + CodePartDjType.Enum: 'Enum', + CodePartDjType.Map: 'Map', + CodePartDjType.EmptyLine: 'EmptyLine', + CodePartDjType.VariableDeclaration: 'VariableDeclaration', + CodePartDjType.SingleLine: 'SingleLine', + CodePartDjType.Export: 'Export', + CodePartDjType.BaseWidget: 'BaseWidget', }; diff --git a/lib/main/djs/code_djs/single_line.dart b/lib/main/djs/code_djs/single_line.dart new file mode 100644 index 0000000..7f4c435 --- /dev/null +++ b/lib/main/djs/code_djs/single_line.dart @@ -0,0 +1,35 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:dj/main/main.dart'; + +part 'single_line.g.dart'; + +@JsonSerializable() +class SingleLineDj extends CodePartDj { + @JsonKey(name: 'line') + final String? line; + + SingleLineDj({ + descriptionDj, + this.line, + CodePartDjType codePartDjType = CodePartDjType.SingleLine, + }) : super( + descriptionDj: descriptionDj, + codePartDjType: codePartDjType, + ); + + factory SingleLineDj.fromJson(Map json) => + _$SingleLineDjFromJson(json); + @override + Map toJson() => _$SingleLineDjToJson(this); + + @override + List toCode() { + var codeLines = super.toCode(); + + if (line != null) { + codeLines.add(line!); + } + + return codeLines; + } +} diff --git a/lib/main/djs/code_djs/single_line.g.dart b/lib/main/djs/code_djs/single_line.g.dart new file mode 100644 index 0000000..9bdcb9c --- /dev/null +++ b/lib/main/djs/code_djs/single_line.g.dart @@ -0,0 +1,76 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'single_line.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +SingleLineDj _$SingleLineDjFromJson(Map json) { + return SingleLineDj( + descriptionDj: json['descriptionDj'], + line: json['line'] as String?, + codePartDjType: + _$enumDecode(_$CodePartDjTypeEnumMap, json['codePartDjType']), + ); +} + +Map _$SingleLineDjToJson(SingleLineDj instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('descriptionDj', instance.descriptionDj); + writeNotNull( + 'codePartDjType', _$CodePartDjTypeEnumMap[instance.codePartDjType]); + writeNotNull('line', instance.line); + return val; +} + +K _$enumDecode( + Map enumValues, + Object? source, { + K? unknownValue, +}) { + if (source == null) { + throw ArgumentError( + 'A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}', + ); + } + + return enumValues.entries.singleWhere( + (e) => e.value == source, + orElse: () { + if (unknownValue == null) { + throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}', + ); + } + return MapEntry(unknownValue, enumValues.values.first); + }, + ).key; +} + +const _$CodePartDjTypeEnumMap = { + CodePartDjType.FunctionCall: 'FunctionCall', + CodePartDjType.Function: 'Function', + CodePartDjType.IfElse: 'IfElse', + CodePartDjType.Import: 'Import', + CodePartDjType.StatelessWidget: 'StatelessWidget', + CodePartDjType.Return: 'Return', + CodePartDjType.Class: 'Class', + CodePartDjType.Field: 'Field', + CodePartDjType.Enum: 'Enum', + CodePartDjType.Map: 'Map', + CodePartDjType.EmptyLine: 'EmptyLine', + CodePartDjType.VariableDeclaration: 'VariableDeclaration', + CodePartDjType.SingleLine: 'SingleLine', + CodePartDjType.Export: 'Export', + CodePartDjType.BaseWidget: 'BaseWidget', +}; diff --git a/lib/main/djs/code_djs/stateless_widget.dart b/lib/main/djs/code_djs/stateless_widget.dart deleted file mode 100644 index 86c9dce..0000000 --- a/lib/main/djs/code_djs/stateless_widget.dart +++ /dev/null @@ -1,59 +0,0 @@ -import 'package:json_annotation/json_annotation.dart'; -import 'package:dj/main/main.dart'; - -part 'stateless_widget.g.dart'; - -@JsonSerializable() -class StatelessWidgetDj extends CodePartDj { - @JsonKey(name: 'name') - final String? name; - - @JsonKey(name: 'args') - final List? args; - - @JsonKey(name: 'body') - final List? body; - - StatelessWidgetDj({ - description, - this.name, - this.args, - this.body, - CodePartType type = CodePartType.StatelessWidget, - }) : super( - description: description, - type: type, - ); - - factory StatelessWidgetDj.fromJson(Map json) => - _$StatelessWidgetDjFromJson(json); - @override - Map toJson() => _$StatelessWidgetDjToJson(this); - - @override - List lines() { - var _lines = super.lines(); - - var bodyLines = []; - body?.forEach((body) { - bodyLines += body.lines(); - }); - var bodyStr = bodyLines.join(' '); - - var contructorArgs = args?.map((e) => e.asConstructorArg()).toList() ?? []; - var argsLine = contructorArgs.join(', '); - argsLine = argsLine == '' ? argsLine : '{$argsLine}'; - - var parmeters = args?.map((e) => e.asParameter()).toList() ?? []; - var paramtersStr = parmeters.join(' '); - - var widgetLine = ''; - widgetLine += 'class $name extends StatelessWidget {'; - widgetLine += '$paramtersStr $name($argsLine);'; - widgetLine += '@override Widget build(BuildContext context) { $bodyStr }'; - widgetLine += '}'; - - _lines.add(widgetLine); - return _lines; - } -} diff --git a/lib/main/djs/code_djs/stateless_widget.g.dart b/lib/main/djs/code_djs/stateless_widget.g.dart deleted file mode 100644 index 7ec6e81..0000000 --- a/lib/main/djs/code_djs/stateless_widget.g.dart +++ /dev/null @@ -1,73 +0,0 @@ -// GENERATED CODE - DO NOT MODIFY BY HAND - -part of 'stateless_widget.dart'; - -// ************************************************************************** -// JsonSerializableGenerator -// ************************************************************************** - -StatelessWidgetDj _$StatelessWidgetDjFromJson(Map json) { - return StatelessWidgetDj( - description: json['description'], - name: json['name'] as String?, - args: (json['args'] as List?) - ?.map((e) => FunctionArg.fromJson(e as Map)) - .toList(), - body: (json['body'] as List?) - ?.map((e) => CodePartDj.fromJson(e as Map)) - .toList(), - type: _$enumDecode(_$CodePartTypeEnumMap, json['type']), - ); -} - -Map _$StatelessWidgetDjToJson(StatelessWidgetDj instance) { - final val = {}; - - void writeNotNull(String key, dynamic value) { - if (value != null) { - val[key] = value; - } - } - - writeNotNull('description', instance.description); - writeNotNull('type', _$CodePartTypeEnumMap[instance.type]); - writeNotNull('name', instance.name); - writeNotNull('args', instance.args?.map((e) => e.toJson()).toList()); - writeNotNull('body', instance.body?.map((e) => e.toJson()).toList()); - return val; -} - -K _$enumDecode( - Map enumValues, - Object? source, { - K? unknownValue, -}) { - if (source == null) { - throw ArgumentError( - 'A value must be provided. Supported values: ' - '${enumValues.values.join(', ')}', - ); - } - - return enumValues.entries.singleWhere( - (e) => e.value == source, - orElse: () { - if (unknownValue == null) { - throw ArgumentError( - '`$source` is not one of the supported values: ' - '${enumValues.values.join(', ')}', - ); - } - return MapEntry(unknownValue, enumValues.values.first); - }, - ).key; -} - -const _$CodePartTypeEnumMap = { - CodePartType.FunctionCall: 'FunctionCall', - CodePartType.Function: 'Function', - CodePartType.IfElse: 'IfElse', - CodePartType.Import: 'Import', - CodePartType.StatelessWidget: 'StatelessWidget', - CodePartType.Return: 'Return', -}; diff --git a/lib/main/djs/code_djs/variable_declaration.dart b/lib/main/djs/code_djs/variable_declaration.dart new file mode 100644 index 0000000..0df6bd6 --- /dev/null +++ b/lib/main/djs/code_djs/variable_declaration.dart @@ -0,0 +1,56 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:dj/main/main.dart'; + +part 'variable_declaration.g.dart'; + +@JsonSerializable() +class VariableDeclarationDj extends CodePartDj { + @JsonKey(name: 'dataType') + final VariableType? dataType; + + @JsonKey(name: 'name') + final String? name; + + @JsonKey(name: 'initialValue') + final String? initialValue; + + VariableDeclarationDj({ + descriptionDj, + this.dataType, + this.name, + this.initialValue, + CodePartDjType codePartDjType = CodePartDjType.VariableDeclaration, + }) : super( + descriptionDj: descriptionDj, + codePartDjType: codePartDjType, + ); + + factory VariableDeclarationDj.fromJson(Map json) => + _$VariableDeclarationDjFromJson(json); + @override + Map toJson() => _$VariableDeclarationDjToJson(this); + + @override + List toCode() { + var codeLines = super.toCode(); + + var declarationLine = ''; + + if (dataType != null) { + declarationLine += variableTypeToString(dataType!) + ' '; + } + + if (name != null) { + declarationLine += name! + ' '; + } + + if (initialValue != null) { + declarationLine += ' = ' + initialValue! + ';'; + } else if (declarationLine != '') { + declarationLine += ';'; + } + + codeLines.add(declarationLine); + return codeLines; + } +} diff --git a/lib/main/djs/code_djs/variable_declaration.g.dart b/lib/main/djs/code_djs/variable_declaration.g.dart new file mode 100644 index 0000000..d796fc2 --- /dev/null +++ b/lib/main/djs/code_djs/variable_declaration.g.dart @@ -0,0 +1,102 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'variable_declaration.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +VariableDeclarationDj _$VariableDeclarationDjFromJson( + Map json) { + return VariableDeclarationDj( + descriptionDj: json['descriptionDj'], + dataType: _$enumDecodeNullable(_$VariableTypeEnumMap, json['dataType']), + name: json['name'] as String?, + initialValue: json['initialValue'] as String?, + codePartDjType: + _$enumDecode(_$CodePartDjTypeEnumMap, json['codePartDjType']), + ); +} + +Map _$VariableDeclarationDjToJson( + VariableDeclarationDj instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('descriptionDj', instance.descriptionDj); + writeNotNull( + 'codePartDjType', _$CodePartDjTypeEnumMap[instance.codePartDjType]); + writeNotNull('dataType', _$VariableTypeEnumMap[instance.dataType]); + writeNotNull('name', instance.name); + writeNotNull('initialValue', instance.initialValue); + return val; +} + +K _$enumDecode( + Map enumValues, + Object? source, { + K? unknownValue, +}) { + if (source == null) { + throw ArgumentError( + 'A value must be provided. Supported values: ' + '${enumValues.values.join(', ')}', + ); + } + + return enumValues.entries.singleWhere( + (e) => e.value == source, + orElse: () { + if (unknownValue == null) { + throw ArgumentError( + '`$source` is not one of the supported values: ' + '${enumValues.values.join(', ')}', + ); + } + return MapEntry(unknownValue, enumValues.values.first); + }, + ).key; +} + +K? _$enumDecodeNullable( + Map enumValues, + dynamic source, { + K? unknownValue, +}) { + if (source == null) { + return null; + } + return _$enumDecode(enumValues, source, unknownValue: unknownValue); +} + +const _$VariableTypeEnumMap = { + VariableType.Void: 'Void', + VariableType.String: 'String', + VariableType.StringNullable: 'StringNullable', + VariableType.ListString: 'ListString', + VariableType.ListStringNullable: 'ListStringNullable', + VariableType.Var: 'Var', +}; + +const _$CodePartDjTypeEnumMap = { + CodePartDjType.FunctionCall: 'FunctionCall', + CodePartDjType.Function: 'Function', + CodePartDjType.IfElse: 'IfElse', + CodePartDjType.Import: 'Import', + CodePartDjType.StatelessWidget: 'StatelessWidget', + CodePartDjType.Return: 'Return', + CodePartDjType.Class: 'Class', + CodePartDjType.Field: 'Field', + CodePartDjType.Enum: 'Enum', + CodePartDjType.Map: 'Map', + CodePartDjType.EmptyLine: 'EmptyLine', + CodePartDjType.VariableDeclaration: 'VariableDeclaration', + CodePartDjType.SingleLine: 'SingleLine', + CodePartDjType.Export: 'Export', + CodePartDjType.BaseWidget: 'BaseWidget', +}; diff --git a/lib/main/djs/utils/comments.dart b/lib/main/djs/utils/comments.dart index 611313f..e660265 100644 --- a/lib/main/djs/utils/comments.dart +++ b/lib/main/djs/utils/comments.dart @@ -1,4 +1,4 @@ -List getSingleLineCommectOnMultipleLines(String? line) { +List getSingleLineCommentOnMultipleLines(String? line) { var comments = []; if (line != null) { diff --git a/lib/main/djs/utils/condition.dart b/lib/main/djs/utils/condition.dart index 01e8471..876a498 100644 --- a/lib/main/djs/utils/condition.dart +++ b/lib/main/djs/utils/condition.dart @@ -66,7 +66,7 @@ class Condition { conditionLine = '$conditionLeft'; } - var conditionBody = body?.lines().join(' '); + var conditionBody = body?.toCode().join(' '); var condition = '{ $conditionBody }'; diff --git a/lib/main/djs/utils/dynamic_parameter_parser.dart b/lib/main/djs/utils/dynamic_parameter_parser.dart new file mode 100644 index 0000000..262bc09 --- /dev/null +++ b/lib/main/djs/utils/dynamic_parameter_parser.dart @@ -0,0 +1,8 @@ +dynamic dynamicParameterParser(dynamic parameter) { + switch (parameter.runtimeType) { + case String: + return '\'$parameter\''; + default: + return parameter; + } +} diff --git a/lib/main/djs/utils/function_args.g.dart b/lib/main/djs/utils/function_args.g.dart index b96eca4..8181420 100644 --- a/lib/main/djs/utils/function_args.g.dart +++ b/lib/main/djs/utils/function_args.g.dart @@ -70,4 +70,7 @@ const _$VariableTypeEnumMap = { VariableType.Void: 'Void', VariableType.String: 'String', VariableType.StringNullable: 'StringNullable', + VariableType.ListString: 'ListString', + VariableType.ListStringNullable: 'ListStringNullable', + VariableType.Var: 'Var', }; diff --git a/lib/main/djs/utils/utils.dart b/lib/main/djs/utils/utils.dart index dee65c3..739057f 100644 --- a/lib/main/djs/utils/utils.dart +++ b/lib/main/djs/utils/utils.dart @@ -2,3 +2,4 @@ export 'comments.dart'; export 'function_args.dart'; export 'variable_types.dart'; export 'condition.dart'; +export 'dynamic_parameter_parser.dart'; diff --git a/lib/main/djs/utils/variable_types.dart b/lib/main/djs/utils/variable_types.dart index 0b44f89..742ae78 100644 --- a/lib/main/djs/utils/variable_types.dart +++ b/lib/main/djs/utils/variable_types.dart @@ -2,6 +2,10 @@ enum VariableType { Void, String, StringNullable, + ListString, + ListStringNullable, + Var, + // Don't forget to handle Newly Added Variable Types in function below } String variableTypeToString(VariableType type) { @@ -12,6 +16,12 @@ String variableTypeToString(VariableType type) { return 'String'; case VariableType.StringNullable: return 'String?'; + case VariableType.ListString: + return 'List'; + case VariableType.ListStringNullable: + return 'List?'; + case VariableType.Var: + return 'var'; default: return 'UNKNOWN_VARIABLE_TYPE'; } diff --git a/pubspec.yaml b/pubspec.yaml index d8644bf..8a9b3a3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,6 +11,8 @@ environment: dependencies: json_annotation: ^4.0.1 path: ^1.8.0 + # flutter: + # sdk: flutter dev_dependencies: json_serializable: ^4.1.0