This repository has been archived by the owner on Oct 2, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8993143
commit 28283a2
Showing
42 changed files
with
1,240 additions
and
363 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
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,134 @@ | ||
import 'package:artemis/generator/data_printer.dart'; | ||
import 'package:artemis/generator/data/definition.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
abstract class Annotation extends Equatable with DataPrinter { | ||
String toAnnotation(); | ||
} | ||
|
||
class JsonKeyItem extends Equatable with DataPrinter { | ||
final String? defaultValue; | ||
|
||
final String? disallowNullValue; | ||
|
||
final String? fromJson; | ||
|
||
final String? ignore; | ||
|
||
final String? includeIfNull; | ||
|
||
final String? name; | ||
|
||
final String? required; | ||
|
||
final String? toJson; | ||
|
||
final String? unknownEnumValue; | ||
|
||
const JsonKeyItem({ | ||
this.defaultValue, | ||
this.disallowNullValue, | ||
this.fromJson, | ||
this.ignore, | ||
this.includeIfNull, | ||
this.name, | ||
this.required, | ||
this.toJson, | ||
this.unknownEnumValue, | ||
}); | ||
|
||
@override | ||
Map<String, Object?> get namedProps { | ||
return { | ||
'defaultValue': defaultValue, | ||
'disallowNullValue': disallowNullValue, | ||
'fromJson': fromJson, | ||
'ignore': ignore, | ||
'includeIfNull': includeIfNull, | ||
'name': name, | ||
'required': required, | ||
'toJson': toJson, | ||
'unknownEnumValue': unknownEnumValue, | ||
}; | ||
} | ||
} | ||
|
||
class StringAnnotation extends Annotation { | ||
final String name; | ||
|
||
StringAnnotation({required this.name}); | ||
|
||
@override | ||
String toAnnotation() => name; | ||
|
||
@override | ||
Map<String, Object?> get namedProps => { | ||
'name': name, | ||
}; | ||
} | ||
|
||
class OverrideAnnotation extends StringAnnotation { | ||
OverrideAnnotation() : super(name: 'override'); | ||
} | ||
|
||
class JsonKeyAnnotation extends Annotation { | ||
final JsonKeyItem jsonKey; | ||
|
||
JsonKeyAnnotation({required this.jsonKey}); | ||
|
||
factory JsonKeyAnnotation.fromMap(Map<String, dynamic> jsonKeyAnnotation) { | ||
return JsonKeyAnnotation( | ||
jsonKey: JsonKeyItem( | ||
defaultValue: jsonKeyAnnotation['defaultValue'] as String?, | ||
disallowNullValue: jsonKeyAnnotation['disallowNullValue'] as String?, | ||
fromJson: jsonKeyAnnotation['fromJson'] as String?, | ||
ignore: jsonKeyAnnotation['ignore'] as String?, | ||
includeIfNull: jsonKeyAnnotation['includeIfNull'] as String?, | ||
name: jsonKeyAnnotation['name'] as String?, | ||
required: jsonKeyAnnotation['required'] as String?, | ||
toJson: jsonKeyAnnotation['toJson'] as String?, | ||
unknownEnumValue: jsonKeyAnnotation['unknownEnumValue'] as String?, | ||
), | ||
); | ||
} | ||
|
||
@override | ||
String toAnnotation() { | ||
final jsonKeyAnnotation = <String, dynamic>{ | ||
'disallowNullValue': jsonKey.disallowNullValue, | ||
'fromJson': jsonKey.fromJson, | ||
'ignore': jsonKey.ignore, | ||
'includeIfNull': jsonKey.includeIfNull, | ||
'name': jsonKey.name, | ||
'required': jsonKey.required, | ||
'toJson': jsonKey.toJson, | ||
'unknownEnumValue': jsonKey.unknownEnumValue | ||
}; | ||
|
||
final key = jsonKeyAnnotation.entries | ||
.map<String?>((e) { | ||
if (e.value != null) { | ||
switch (e.key) { | ||
case 'name': | ||
return '${e.key}: \'${e.value}\''; | ||
default: | ||
return '${e.key}: ${e.value}'; | ||
} | ||
} | ||
|
||
return null; | ||
}) | ||
.whereType<String>() | ||
.join(', '); | ||
|
||
return 'JsonKey($key)'; | ||
} | ||
|
||
@override | ||
Map<String, Object?> get namedProps { | ||
return { | ||
'jsonKey': jsonKey, | ||
}; | ||
} | ||
} |
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
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.