-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from ARK4579/develop
flutter widget parsing udpates
- Loading branch information
Showing
44 changed files
with
1,732 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String, dynamic> json) => | ||
_$BaseWidgetDjFromJson(json); | ||
@override | ||
Map<String, dynamic> toJson() => _$BaseWidgetDjToJson(this); | ||
|
||
@override | ||
List<String> toCode() { | ||
return super.toCode(); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<FieldDj>? fields; | ||
|
||
@JsonKey(name: 'isExtends') | ||
final bool? isExtends; | ||
|
||
@JsonKey(name: 'isImplements') | ||
final bool? isImplements; | ||
|
||
@JsonKey(name: 'jsonSerializable') | ||
final bool? jsonSerializable; | ||
|
||
@JsonKey(name: 'functions') | ||
final List<CodePartDj>? 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<String, dynamic> json) => | ||
_$ClassDjFromJson(json); | ||
@override | ||
Map<String, dynamic> toJson() => _$ClassDjToJson(this); | ||
|
||
List<String> _constructorCode() { | ||
var codeLines = <String>[]; | ||
|
||
codeLines.add('$name({'); | ||
|
||
var superOnlyFields = <FieldDj>[]; | ||
|
||
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<String> 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<String, dynamic> 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<String, dynamic> toJson() => _\$${name}ToJson(this);'); | ||
} | ||
|
||
// class end line | ||
_lines.add('}'); | ||
|
||
return _lines; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.