File tree 8 files changed +30
-2
lines changed
json_syntax_generator/lib/src
native_assets_cli/lib/src
8 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ void main(List<String> args) {
45
45
'HookOutput' ,
46
46
'LinkOutput' ,
47
47
],
48
+ visbleUnionTagValues: ['Asset' ],
48
49
).analyze ();
49
50
final textDumpFile = File .fromUri (
50
51
packageUri.resolve (
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ class ClassGenerator {
27
27
buffer.writeln ('''
28
28
class $className $extendsString {
29
29
''' );
30
+ buffer.writeln (_generateTag ());
30
31
buffer.writeln (_generateFields ());
31
32
buffer.writeln (_generateJsonFactory ());
32
33
buffer.writeln (_generateJsonConstructor ());
@@ -41,6 +42,16 @@ class $className $extendsString {
41
42
''' );
42
43
}
43
44
45
+ /// If this is a tagged union value, expose the tag.
46
+ String _generateTag () {
47
+ if (classInfo.superclass? .visibleTaggedUnion != true ) return '' ;
48
+ final tagProperty = classInfo.superclass! .taggedUnionProperty;
49
+ final tagValue = classInfo.taggedUnionValue;
50
+ return '''
51
+ static const ${tagProperty }Value = '$tagValue ';
52
+ ''' ;
53
+ }
54
+
44
55
String _generateFields () {
45
56
if (classInfo.superclass != null ) {
46
57
// The super class already has the required fields.
Original file line number Diff line number Diff line change @@ -40,6 +40,11 @@ class NormalClassInfo extends ClassInfo {
40
40
/// Only set in the sub classes.
41
41
final String ? taggedUnionValue;
42
42
43
+ /// If the tagged union tags are available in the generated API.
44
+ ///
45
+ /// Only set in the parent class.
46
+ final bool visibleTaggedUnion;
47
+
43
48
bool get isTaggedUnion =>
44
49
taggedUnionProperty != null || taggedUnionValue != null ;
45
50
@@ -52,6 +57,7 @@ class NormalClassInfo extends ClassInfo {
52
57
this .taggedUnionProperty,
53
58
this .taggedUnionValue,
54
59
this .extraValidation = const [],
60
+ this .visibleTaggedUnion = false ,
55
61
}) : super () {
56
62
superclass? .subclasses.add (this );
57
63
if (taggedUnionValue != null ) {
@@ -77,6 +83,7 @@ $propertiesString
77
83
],
78
84
taggedUnionProperty: $taggedUnionProperty ,
79
85
taggedUnionValue: $taggedUnionValue ,
86
+ visibleTaggedUnion: $visibleTaggedUnion ,
80
87
extraValidation: [
81
88
$extraValidationString
82
89
],
Original file line number Diff line number Diff line change @@ -44,11 +44,15 @@ class SchemaAnalyzer {
44
44
/// Generate public setters for these class names.
45
45
final List <String > publicSetters;
46
46
47
+ /// For subtypes of these classes, the union tag values are exposed.
48
+ final List <String > visbleUnionTagValues;
49
+
47
50
SchemaAnalyzer (
48
51
this .schema, {
49
52
this .capitalizationOverrides = const {},
50
53
this .classSorting,
51
54
this .publicSetters = const [],
55
+ this .visbleUnionTagValues = const [],
52
56
});
53
57
54
58
/// Accumulator for all classes during the analysis.
@@ -164,6 +168,7 @@ class SchemaAnalyzer {
164
168
taggedUnionValue: taggedUnionValue,
165
169
taggedUnionProperty:
166
170
schemas.generateSubClasses ? properties.single.name : null ,
171
+ visibleTaggedUnion: visbleUnionTagValues.contains (typeName),
167
172
extraValidation: extraValidation,
168
173
);
169
174
_classes[typeName] = classInfo;
Original file line number Diff line number Diff line change @@ -171,7 +171,7 @@ extension CodeAssetType on CodeAsset {
171
171
// TODO(https://github.com/dart-lang/native/issues/2132): Change to be
172
172
// namespaced by package name. (We'll temporarily need to support both the
173
173
// old a new type.)
174
- static const String type = 'native_code' ;
174
+ static const String type = syntax. NativeCodeAsset .typeValue ;
175
175
}
176
176
177
177
extension EncodedCodeAsset on EncodedAsset {
Original file line number Diff line number Diff line change @@ -815,6 +815,8 @@ class MacOSCodeConfig {
815
815
}
816
816
817
817
class NativeCodeAsset extends Asset {
818
+ static const typeValue = 'native_code' ;
819
+
818
820
NativeCodeAsset .fromJson (super .json, {super .path}) : super ._fromJson ();
819
821
820
822
NativeCodeAsset ({
Original file line number Diff line number Diff line change @@ -84,7 +84,7 @@ extension DataAssetType on DataAsset {
84
84
// TODO(https://github.com/dart-lang/native/issues/2132): Change to be
85
85
// namespaced by package name. (We'll temporarily need to support both the
86
86
// old a new type.)
87
- static const String type = 'data' ;
87
+ static const String type = syntax. DataAsset .typeValue ;
88
88
}
89
89
90
90
extension EncodedDataAsset on EncodedAsset {
Original file line number Diff line number Diff line change @@ -50,6 +50,8 @@ class Asset {
50
50
}
51
51
52
52
class DataAsset extends Asset {
53
+ static const typeValue = 'data' ;
54
+
53
55
DataAsset .fromJson (super .json, {super .path}) : super ._fromJson ();
54
56
55
57
DataAsset ({
You can’t perform that action at this time.
0 commit comments