-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for serializing xml cdata (#48)
- Loading branch information
Showing
29 changed files
with
1,501 additions
and
164 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/// An annotation used to specify how a CDATA is serialized. | ||
class XmlCDATA { | ||
const XmlCDATA(); | ||
} |
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
30 changes: 30 additions & 0 deletions
30
xml_serializable/lib/src/builder_generators/xml_cdata_builder_generator.dart
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,30 @@ | ||
import 'builder_generator.dart'; | ||
|
||
class XmlCDATABuilderGenerator extends BuilderGenerator { | ||
/// If `false` (the default) then the type does not represent a nullable type. | ||
final bool _isNullable; | ||
|
||
const XmlCDATABuilderGenerator({bool isNullable = false}) | ||
: _isNullable = isNullable; | ||
|
||
@override | ||
String generateBuilder(String expression, {String builder = 'builder'}) { | ||
final buffer = StringBuffer(); | ||
|
||
if (_isNullable) { | ||
buffer.write('if ($expression != null) { '); | ||
} | ||
|
||
buffer.write('$builder.cdata($expression);'); | ||
|
||
if (_isNullable) { | ||
buffer.write(' }'); | ||
} | ||
|
||
return buffer.toString(); | ||
} | ||
} | ||
|
||
class NullableXmlCDATABuilderGenerator extends XmlCDATABuilderGenerator { | ||
const NullableXmlCDATABuilderGenerator() : super(isNullable: true); | ||
} |
31 changes: 31 additions & 0 deletions
31
xml_serializable/lib/src/constructor_generators/xml_cdata_constructor_generator.dart
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,31 @@ | ||
import 'constructor_generator.dart'; | ||
|
||
class XmlCDATAConstructorGenerator extends ConstructorGenerator { | ||
/// If `false` (the default) then the type does not represent a nullable type. | ||
final bool _isNullable; | ||
|
||
const XmlCDATAConstructorGenerator({bool isNullable = false}) | ||
: _isNullable = isNullable; | ||
|
||
@override | ||
String generateConstructor(String expression) { | ||
final buffer = StringBuffer(); | ||
|
||
if (_isNullable) { | ||
buffer.write('$expression != null ? '); | ||
} | ||
|
||
buffer.write('XmlCDATA($expression)'); | ||
|
||
if (_isNullable) { | ||
buffer.write(' : null'); | ||
} | ||
|
||
return buffer.toString(); | ||
} | ||
} | ||
|
||
class NullableXmlCDATAConstructorGenerator | ||
extends XmlCDATAConstructorGenerator { | ||
const NullableXmlCDATAConstructorGenerator() : super(isNullable: true); | ||
} |
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
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
26 changes: 26 additions & 0 deletions
26
xml_serializable/lib/src/getter_generators/xml_cdata_getter_generator.dart
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,26 @@ | ||
import 'getter_generator.dart'; | ||
|
||
class XmlCDATAGetterGenerator extends GetterGenerator { | ||
/// If `false` (the default) then the type does not represent a nullable type. | ||
final bool _isNullable; | ||
|
||
const XmlCDATAGetterGenerator({bool isNullable = false}) | ||
: _isNullable = isNullable; | ||
|
||
@override | ||
String generateGetter(String expression) { | ||
final buffer = StringBuffer(expression); | ||
|
||
buffer.write('.getCDATA()'); | ||
|
||
if (!_isNullable) { | ||
buffer.write('!'); | ||
} | ||
|
||
return buffer.toString(); | ||
} | ||
} | ||
|
||
class NullableXmlCDATAGetterGenerator extends XmlCDATAGetterGenerator { | ||
const NullableXmlCDATAGetterGenerator() : super(isNullable: true); | ||
} |
8 changes: 8 additions & 0 deletions
8
xml_serializable/lib/src/type_checkers/xml_cdata_type_checker.dart
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,8 @@ | ||
import 'package:source_gen/source_gen.dart'; | ||
import 'package:xml_annotation/xml_annotation.dart'; | ||
|
||
/// A [TypeChecker] for [XmlCDATA]. | ||
@Deprecated( | ||
'Use element.isXmlCDATA instead of xmlCDATATypeChecker.hasAnnotationOf(element).', | ||
) | ||
const xmlCDATATypeChecker = TypeChecker.fromRuntime(XmlCDATA); |
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.