mirror of
https://github.com/flutter/packages.git
synced 2025-07-01 07:08:10 +08:00
[pigeon] Change generator formatting to closer match formatter output (#3072)
* dart and some java * java * objc header * objc source * newln * loopable new lines * better counting * cpp and redo previous changes * changelog * nest and nits * addScoped * rewrite description of newln * regex tests
This commit is contained in:
@ -1,3 +1,8 @@
|
|||||||
|
## 7.0.1
|
||||||
|
|
||||||
|
* [generator_tools] adds `newln` method for adding empty lines and ending lines.
|
||||||
|
* Updates generators to more closely match Flutter formatter tool output.
|
||||||
|
|
||||||
## 7.0.0
|
## 7.0.0
|
||||||
|
|
||||||
* [java] **BREAKING CHANGE**: Makes data classes final.
|
* [java] **BREAKING CHANGE**: Makes data classes final.
|
||||||
|
@ -104,7 +104,7 @@ class CppHeaderGenerator extends StructuredGenerator<CppOptions> {
|
|||||||
}
|
}
|
||||||
indent.writeln('$_commentPrefix $generatedCodeWarning');
|
indent.writeln('$_commentPrefix $generatedCodeWarning');
|
||||||
indent.writeln('$_commentPrefix $seeAlsoWarning');
|
indent.writeln('$_commentPrefix $seeAlsoWarning');
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -119,34 +119,34 @@ class CppHeaderGenerator extends StructuredGenerator<CppOptions> {
|
|||||||
'flutter/encodable_value.h',
|
'flutter/encodable_value.h',
|
||||||
'flutter/standard_message_codec.h',
|
'flutter/standard_message_codec.h',
|
||||||
]);
|
]);
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
_writeSystemHeaderIncludeBlock(indent, <String>[
|
_writeSystemHeaderIncludeBlock(indent, <String>[
|
||||||
'map',
|
'map',
|
||||||
'string',
|
'string',
|
||||||
'optional',
|
'optional',
|
||||||
]);
|
]);
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
if (generatorOptions.namespace != null) {
|
if (generatorOptions.namespace != null) {
|
||||||
indent.writeln('namespace ${generatorOptions.namespace} {');
|
indent.writeln('namespace ${generatorOptions.namespace} {');
|
||||||
}
|
}
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
if (generatorOptions.namespace?.endsWith('_pigeontest') ?? false) {
|
if (generatorOptions.namespace?.endsWith('_pigeontest') ?? false) {
|
||||||
final String testFixtureClass =
|
final String testFixtureClass =
|
||||||
'${_pascalCaseFromSnakeCase(generatorOptions.namespace!.replaceAll('_pigeontest', ''))}Test';
|
'${_pascalCaseFromSnakeCase(generatorOptions.namespace!.replaceAll('_pigeontest', ''))}Test';
|
||||||
indent.writeln('class $testFixtureClass;');
|
indent.writeln('class $testFixtureClass;');
|
||||||
}
|
}
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
indent.writeln('$_commentPrefix Generated class from Pigeon.');
|
indent.writeln('$_commentPrefix Generated class from Pigeon.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void writeEnum(
|
void writeEnum(
|
||||||
CppOptions generatorOptions, Root root, Indent indent, Enum anEnum) {
|
CppOptions generatorOptions, Root root, Indent indent, Enum anEnum) {
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
addDocumentationComments(
|
addDocumentationComments(
|
||||||
indent, anEnum.documentationComments, _docCommentSpec);
|
indent, anEnum.documentationComments, _docCommentSpec);
|
||||||
indent.write('enum class ${anEnum.name} ');
|
indent.write('enum class ${anEnum.name} ');
|
||||||
indent.scoped('{', '};', () {
|
indent.addScoped('{', '};', () {
|
||||||
enumerate(anEnum.members, (int index, final EnumMember member) {
|
enumerate(anEnum.members, (int index, final EnumMember member) {
|
||||||
addDocumentationComments(
|
addDocumentationComments(
|
||||||
indent, member.documentationComments, _docCommentSpec);
|
indent, member.documentationComments, _docCommentSpec);
|
||||||
@ -173,7 +173,7 @@ class CppHeaderGenerator extends StructuredGenerator<CppOptions> {
|
|||||||
testFixtureClass =
|
testFixtureClass =
|
||||||
'${_pascalCaseFromSnakeCase(generatorOptions.namespace!.replaceAll('_pigeontest', ''))}Test';
|
'${_pascalCaseFromSnakeCase(generatorOptions.namespace!.replaceAll('_pigeontest', ''))}Test';
|
||||||
}
|
}
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
|
|
||||||
const List<String> generatedMessages = <String>[
|
const List<String> generatedMessages = <String>[
|
||||||
' Generated class from Pigeon that represents data sent in messages.'
|
' Generated class from Pigeon that represents data sent in messages.'
|
||||||
@ -184,8 +184,8 @@ class CppHeaderGenerator extends StructuredGenerator<CppOptions> {
|
|||||||
generatorComments: generatedMessages);
|
generatorComments: generatedMessages);
|
||||||
|
|
||||||
indent.write('class ${klass.name} ');
|
indent.write('class ${klass.name} ');
|
||||||
indent.scoped('{', '};', () {
|
indent.addScoped('{', '};', () {
|
||||||
indent.scoped(' public:', '', () {
|
indent.addScoped(' public:', '', () {
|
||||||
indent.writeln('${klass.name}();');
|
indent.writeln('${klass.name}();');
|
||||||
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
|
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
|
||||||
addDocumentationComments(
|
addDocumentationComments(
|
||||||
@ -204,11 +204,11 @@ class CppHeaderGenerator extends StructuredGenerator<CppOptions> {
|
|||||||
indent.writeln(
|
indent.writeln(
|
||||||
'void ${_makeSetterName(field)}(${_unownedArgumentType(nonNullType)} value_arg);');
|
'void ${_makeSetterName(field)}(${_unownedArgumentType(nonNullType)} value_arg);');
|
||||||
}
|
}
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
indent.scoped(' private:', '', () {
|
indent.addScoped(' private:', '', () {
|
||||||
indent.writeln('${klass.name}(const flutter::EncodableList& list);');
|
indent.writeln('${klass.name}(const flutter::EncodableList& list);');
|
||||||
indent.writeln('flutter::EncodableList ToEncodableList() const;');
|
indent.writeln('flutter::EncodableList ToEncodableList() const;');
|
||||||
for (final Class friend in root.classes) {
|
for (final Class friend in root.classes) {
|
||||||
@ -236,7 +236,7 @@ class CppHeaderGenerator extends StructuredGenerator<CppOptions> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, nestCount: 0);
|
}, nestCount: 0);
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -256,14 +256,14 @@ class CppHeaderGenerator extends StructuredGenerator<CppOptions> {
|
|||||||
addDocumentationComments(indent, api.documentationComments, _docCommentSpec,
|
addDocumentationComments(indent, api.documentationComments, _docCommentSpec,
|
||||||
generatorComments: generatedMessages);
|
generatorComments: generatedMessages);
|
||||||
indent.write('class ${api.name} ');
|
indent.write('class ${api.name} ');
|
||||||
indent.scoped('{', '};', () {
|
indent.addScoped('{', '};', () {
|
||||||
indent.scoped(' private:', '', () {
|
indent.addScoped(' private:', '', () {
|
||||||
indent.writeln('flutter::BinaryMessenger* binary_messenger_;');
|
indent.writeln('flutter::BinaryMessenger* binary_messenger_;');
|
||||||
});
|
});
|
||||||
indent.scoped(' public:', '', () {
|
indent.addScoped(' public:', '', () {
|
||||||
indent
|
indent
|
||||||
.write('${api.name}(flutter::BinaryMessenger* binary_messenger);');
|
.write('${api.name}(flutter::BinaryMessenger* binary_messenger);');
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
indent
|
indent
|
||||||
.writeln('static const flutter::StandardMessageCodec& GetCodec();');
|
.writeln('static const flutter::StandardMessageCodec& GetCodec();');
|
||||||
for (final Method func in api.methods) {
|
for (final Method func in api.methods) {
|
||||||
@ -288,7 +288,7 @@ class CppHeaderGenerator extends StructuredGenerator<CppOptions> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, nestCount: 0);
|
}, nestCount: 0);
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -308,8 +308,8 @@ class CppHeaderGenerator extends StructuredGenerator<CppOptions> {
|
|||||||
addDocumentationComments(indent, api.documentationComments, _docCommentSpec,
|
addDocumentationComments(indent, api.documentationComments, _docCommentSpec,
|
||||||
generatorComments: generatedMessages);
|
generatorComments: generatedMessages);
|
||||||
indent.write('class ${api.name} ');
|
indent.write('class ${api.name} ');
|
||||||
indent.scoped('{', '};', () {
|
indent.addScoped('{', '};', () {
|
||||||
indent.scoped(' public:', '', () {
|
indent.addScoped(' public:', '', () {
|
||||||
indent.writeln('${api.name}(const ${api.name}&) = delete;');
|
indent.writeln('${api.name}(const ${api.name}&) = delete;');
|
||||||
indent.writeln('${api.name}& operator=(const ${api.name}&) = delete;');
|
indent.writeln('${api.name}& operator=(const ${api.name}&) = delete;');
|
||||||
indent.writeln('virtual ~${api.name}() { };');
|
indent.writeln('virtual ~${api.name}() { };');
|
||||||
@ -347,7 +347,7 @@ class CppHeaderGenerator extends StructuredGenerator<CppOptions> {
|
|||||||
'virtual $returnTypeName ${_makeMethodName(method)}(${argSignature.join(', ')}) = 0;');
|
'virtual $returnTypeName ${_makeMethodName(method)}(${argSignature.join(', ')}) = 0;');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
indent.writeln('$_commentPrefix The codec used by ${api.name}.');
|
indent.writeln('$_commentPrefix The codec used by ${api.name}.');
|
||||||
indent
|
indent
|
||||||
.writeln('static const flutter::StandardMessageCodec& GetCodec();');
|
.writeln('static const flutter::StandardMessageCodec& GetCodec();');
|
||||||
@ -360,7 +360,7 @@ class CppHeaderGenerator extends StructuredGenerator<CppOptions> {
|
|||||||
indent.writeln(
|
indent.writeln(
|
||||||
'static flutter::EncodableValue WrapError(const FlutterError& error);');
|
'static flutter::EncodableValue WrapError(const FlutterError& error);');
|
||||||
});
|
});
|
||||||
indent.scoped(' protected:', '', () {
|
indent.addScoped(' protected:', '', () {
|
||||||
indent.writeln('${api.name}() = default;');
|
indent.writeln('${api.name}() = default;');
|
||||||
});
|
});
|
||||||
}, nestCount: 0);
|
}, nestCount: 0);
|
||||||
@ -372,9 +372,9 @@ class CppHeaderGenerator extends StructuredGenerator<CppOptions> {
|
|||||||
final String codeSerializerName = _getCodecSerializerName(api);
|
final String codeSerializerName = _getCodecSerializerName(api);
|
||||||
indent
|
indent
|
||||||
.write('class $codeSerializerName : public $_defaultCodecSerializer ');
|
.write('class $codeSerializerName : public $_defaultCodecSerializer ');
|
||||||
indent.scoped('{', '};', () {
|
indent.addScoped('{', '};', () {
|
||||||
indent.scoped(' public:', '', () {
|
indent.addScoped(' public:', '', () {
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
indent.format('''
|
indent.format('''
|
||||||
inline static $codeSerializerName& GetInstance() {
|
inline static $codeSerializerName& GetInstance() {
|
||||||
\tstatic $codeSerializerName sInstance;
|
\tstatic $codeSerializerName sInstance;
|
||||||
@ -392,7 +392,7 @@ inline static $codeSerializerName& GetInstance() {
|
|||||||
'flutter::EncodableValue ReadValueOfType(uint8_t type, flutter::ByteStreamReader* stream) const override;');
|
'flutter::EncodableValue ReadValueOfType(uint8_t type, flutter::ByteStreamReader* stream) const override;');
|
||||||
});
|
});
|
||||||
}, nestCount: 0);
|
}, nestCount: 0);
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _writeErrorOr(Indent indent,
|
void _writeErrorOr(Indent indent,
|
||||||
@ -468,28 +468,28 @@ class CppSourceGenerator extends StructuredGenerator<CppOptions> {
|
|||||||
}
|
}
|
||||||
indent.writeln('$_commentPrefix $generatedCodeWarning');
|
indent.writeln('$_commentPrefix $generatedCodeWarning');
|
||||||
indent.writeln('$_commentPrefix $seeAlsoWarning');
|
indent.writeln('$_commentPrefix $seeAlsoWarning');
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
indent.addln('#undef _HAS_EXCEPTIONS');
|
indent.addln('#undef _HAS_EXCEPTIONS');
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void writeFileImports(CppOptions generatorOptions, Root root, Indent indent) {
|
void writeFileImports(CppOptions generatorOptions, Root root, Indent indent) {
|
||||||
indent.writeln('#include "${generatorOptions.headerIncludePath}"');
|
indent.writeln('#include "${generatorOptions.headerIncludePath}"');
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
_writeSystemHeaderIncludeBlock(indent, <String>[
|
_writeSystemHeaderIncludeBlock(indent, <String>[
|
||||||
'flutter/basic_message_channel.h',
|
'flutter/basic_message_channel.h',
|
||||||
'flutter/binary_messenger.h',
|
'flutter/binary_messenger.h',
|
||||||
'flutter/encodable_value.h',
|
'flutter/encodable_value.h',
|
||||||
'flutter/standard_message_codec.h',
|
'flutter/standard_message_codec.h',
|
||||||
]);
|
]);
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
_writeSystemHeaderIncludeBlock(indent, <String>[
|
_writeSystemHeaderIncludeBlock(indent, <String>[
|
||||||
'map',
|
'map',
|
||||||
'string',
|
'string',
|
||||||
'optional',
|
'optional',
|
||||||
]);
|
]);
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -508,9 +508,9 @@ class CppSourceGenerator extends StructuredGenerator<CppOptions> {
|
|||||||
final Set<String> customEnumNames =
|
final Set<String> customEnumNames =
|
||||||
root.enums.map((Enum x) => x.name).toSet();
|
root.enums.map((Enum x) => x.name).toSet();
|
||||||
|
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
indent.writeln('$_commentPrefix ${klass.name}');
|
indent.writeln('$_commentPrefix ${klass.name}');
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
|
|
||||||
// Getters and setters.
|
// Getters and setters.
|
||||||
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
|
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
|
||||||
@ -523,7 +523,7 @@ class CppSourceGenerator extends StructuredGenerator<CppOptions> {
|
|||||||
|
|
||||||
// Default constructor.
|
// Default constructor.
|
||||||
indent.writeln('${klass.name}::${klass.name}() {}');
|
indent.writeln('${klass.name}::${klass.name}() {}');
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
|
|
||||||
// Deserialization.
|
// Deserialization.
|
||||||
writeClassDecode(generatorOptions, root, indent, klass, customClassNames,
|
writeClassDecode(generatorOptions, root, indent, klass, customClassNames,
|
||||||
@ -541,8 +541,8 @@ class CppSourceGenerator extends StructuredGenerator<CppOptions> {
|
|||||||
) {
|
) {
|
||||||
indent.write(
|
indent.write(
|
||||||
'flutter::EncodableList ${klass.name}::ToEncodableList() const ');
|
'flutter::EncodableList ${klass.name}::ToEncodableList() const ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.scoped('return flutter::EncodableList{', '};', () {
|
indent.addScoped('return flutter::EncodableList{', '};', () {
|
||||||
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
|
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
|
||||||
final HostDatatype hostDatatype = getFieldHostDatatype(
|
final HostDatatype hostDatatype = getFieldHostDatatype(
|
||||||
field, root.classes, root.enums, _baseCppTypeForBuiltinDartType);
|
field, root.classes, root.enums, _baseCppTypeForBuiltinDartType);
|
||||||
@ -552,7 +552,7 @@ class CppSourceGenerator extends StructuredGenerator<CppOptions> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -566,7 +566,7 @@ class CppSourceGenerator extends StructuredGenerator<CppOptions> {
|
|||||||
) {
|
) {
|
||||||
indent.write(
|
indent.write(
|
||||||
'${klass.name}::${klass.name}(const flutter::EncodableList& list) ');
|
'${klass.name}::${klass.name}(const flutter::EncodableList& list) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
enumerate(getFieldsInSerializationOrder(klass),
|
enumerate(getFieldsInSerializationOrder(klass),
|
||||||
(int index, final NamedType field) {
|
(int index, final NamedType field) {
|
||||||
final String instanceVariableName = _makeInstanceVariableName(field);
|
final String instanceVariableName = _makeInstanceVariableName(field);
|
||||||
@ -593,21 +593,20 @@ else if (const int64_t* ${pointerFieldName}_64 = std::get_if<int64_t>(&$encodabl
|
|||||||
.contains(field.type.baseName)) {
|
.contains(field.type.baseName)) {
|
||||||
indent.write(
|
indent.write(
|
||||||
'if (const flutter::EncodableList* $pointerFieldName = std::get_if<flutter::EncodableList>(&$encodableFieldName)) ');
|
'if (const flutter::EncodableList* $pointerFieldName = std::get_if<flutter::EncodableList>(&$encodableFieldName)) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'$instanceVariableName = ${hostDatatype.datatype}(*$pointerFieldName);');
|
'$instanceVariableName = ${hostDatatype.datatype}(*$pointerFieldName);');
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
indent.write(
|
indent.write(
|
||||||
'if (const ${hostDatatype.datatype}* $pointerFieldName = std::get_if<${hostDatatype.datatype}>(&$encodableFieldName)) ');
|
'if (const ${hostDatatype.datatype}* $pointerFieldName = std::get_if<${hostDatatype.datatype}>(&$encodableFieldName)) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('$instanceVariableName = *$pointerFieldName;');
|
indent.writeln('$instanceVariableName = *$pointerFieldName;');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
indent.addln('');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -625,10 +624,10 @@ else if (const int64_t* ${pointerFieldName}_64 = std::get_if<int64_t>(&$encodabl
|
|||||||
'$_commentPrefix Generated class from Pigeon that represents Flutter messages that can be called from C++.');
|
'$_commentPrefix Generated class from Pigeon that represents Flutter messages that can be called from C++.');
|
||||||
indent.write(
|
indent.write(
|
||||||
'${api.name}::${api.name}(flutter::BinaryMessenger* binary_messenger) ');
|
'${api.name}::${api.name}(flutter::BinaryMessenger* binary_messenger) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('this->binary_messenger_ = binary_messenger;');
|
indent.writeln('this->binary_messenger_ = binary_messenger;');
|
||||||
});
|
});
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
final String codeSerializerName = getCodecClasses(api, root).isNotEmpty
|
final String codeSerializerName = getCodecClasses(api, root).isNotEmpty
|
||||||
? _getCodecSerializerName(api)
|
? _getCodecSerializerName(api)
|
||||||
: _defaultCodecSerializer;
|
: _defaultCodecSerializer;
|
||||||
@ -657,7 +656,7 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() {
|
|||||||
];
|
];
|
||||||
indent.write(
|
indent.write(
|
||||||
'void ${api.name}::${_makeMethodName(func)}(${parameters.join(', ')}) ');
|
'void ${api.name}::${_makeMethodName(func)}(${parameters.join(', ')}) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.writeScoped('{', '}', () {
|
||||||
const String channel = 'channel';
|
const String channel = 'channel';
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'auto channel = std::make_unique<flutter::BasicMessageChannel<>>(binary_messenger_, '
|
'auto channel = std::make_unique<flutter::BasicMessageChannel<>>(binary_messenger_, '
|
||||||
@ -669,7 +668,7 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() {
|
|||||||
if (func.arguments.isEmpty) {
|
if (func.arguments.isEmpty) {
|
||||||
indent.addln('flutter::EncodableValue();');
|
indent.addln('flutter::EncodableValue();');
|
||||||
} else {
|
} else {
|
||||||
indent.scoped(
|
indent.addScoped(
|
||||||
'flutter::EncodableValue(flutter::EncodableList{', '});', () {
|
'flutter::EncodableValue(flutter::EncodableList{', '});', () {
|
||||||
for (final _HostNamedType param in hostParameters) {
|
for (final _HostNamedType param in hostParameters) {
|
||||||
final String encodedArgument = _wrappedHostApiArgumentExpression(
|
final String encodedArgument = _wrappedHostApiArgumentExpression(
|
||||||
@ -683,7 +682,7 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() {
|
|||||||
// ignore: missing_whitespace_between_adjacent_strings
|
// ignore: missing_whitespace_between_adjacent_strings
|
||||||
'[on_success = std::move(on_success), on_error = std::move(on_error)]'
|
'[on_success = std::move(on_success), on_error = std::move(on_error)]'
|
||||||
'(const uint8_t* reply, size_t reply_size) ');
|
'(const uint8_t* reply, size_t reply_size) ');
|
||||||
indent.scoped('{', '});', () {
|
indent.addScoped('{', '});', () {
|
||||||
final String successCallbackArgument;
|
final String successCallbackArgument;
|
||||||
if (func.returnType.isVoid) {
|
if (func.returnType.isVoid) {
|
||||||
successCallbackArgument = '';
|
successCallbackArgument = '';
|
||||||
@ -725,21 +724,21 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() {
|
|||||||
'$_commentPrefix Sets up an instance of `${api.name}` to handle messages through the `binary_messenger`.');
|
'$_commentPrefix Sets up an instance of `${api.name}` to handle messages through the `binary_messenger`.');
|
||||||
indent.write(
|
indent.write(
|
||||||
'void ${api.name}::SetUp(flutter::BinaryMessenger* binary_messenger, ${api.name}* api) ');
|
'void ${api.name}::SetUp(flutter::BinaryMessenger* binary_messenger, ${api.name}* api) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
for (final Method method in api.methods) {
|
for (final Method method in api.methods) {
|
||||||
final String channelName = makeChannelName(api, method);
|
final String channelName = makeChannelName(api, method);
|
||||||
indent.write('');
|
indent.write('');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'auto channel = std::make_unique<flutter::BasicMessageChannel<>>(binary_messenger, '
|
'auto channel = std::make_unique<flutter::BasicMessageChannel<>>(binary_messenger, '
|
||||||
'"$channelName", &GetCodec());');
|
'"$channelName", &GetCodec());');
|
||||||
indent.write('if (api != nullptr) ');
|
indent.write('if (api != nullptr) ');
|
||||||
indent.scoped('{', '} else {', () {
|
indent.addScoped('{', '} else {', () {
|
||||||
indent.write(
|
indent.write(
|
||||||
'channel->SetMessageHandler([api](const flutter::EncodableValue& message, const flutter::MessageReply<flutter::EncodableValue>& reply) ');
|
'channel->SetMessageHandler([api](const flutter::EncodableValue& message, const flutter::MessageReply<flutter::EncodableValue>& reply) ');
|
||||||
indent.scoped('{', '});', () {
|
indent.addScoped('{', '});', () {
|
||||||
indent.write('try ');
|
indent.write('try ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
final List<String> methodArgument = <String>[];
|
final List<String> methodArgument = <String>[];
|
||||||
if (method.arguments.isNotEmpty) {
|
if (method.arguments.isNotEmpty) {
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
@ -760,7 +759,7 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() {
|
|||||||
'const auto& $encodableArgName = args.at($index);');
|
'const auto& $encodableArgName = args.at($index);');
|
||||||
if (!arg.type.isNullable) {
|
if (!arg.type.isNullable) {
|
||||||
indent.write('if ($encodableArgName.IsNull()) ');
|
indent.write('if ($encodableArgName.IsNull()) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'reply(WrapError("$argName unexpectedly null."));');
|
'reply(WrapError("$argName unexpectedly null."));');
|
||||||
indent.writeln('return;');
|
indent.writeln('return;');
|
||||||
@ -793,9 +792,9 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() {
|
|||||||
indent.writeln('$returnTypeName output = $call;');
|
indent.writeln('$returnTypeName output = $call;');
|
||||||
indent.format(_wrapResponse(indent, root, method.returnType));
|
indent.format(_wrapResponse(indent, root, method.returnType));
|
||||||
}
|
}
|
||||||
});
|
}, addTrailingNewline: false);
|
||||||
indent.write('catch (const std::exception& exception) ');
|
indent.add(' catch (const std::exception& exception) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
// There is a potential here for `reply` to be called twice, which
|
// There is a potential here for `reply` to be called twice, which
|
||||||
// is a violation of the API contract, because there's no way of
|
// is a violation of the API contract, because there's no way of
|
||||||
// knowing whether or not the plugin code called `reply` before
|
// knowing whether or not the plugin code called `reply` before
|
||||||
@ -808,14 +807,14 @@ const flutter::StandardMessageCodec& ${api.name}::GetCodec() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
indent.scoped(null, '}', () {
|
indent.addScoped(null, '}', () {
|
||||||
indent.writeln('channel->SetMessageHandler(nullptr);');
|
indent.writeln('channel->SetMessageHandler(nullptr);');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
indent.format('''
|
indent.format('''
|
||||||
flutter::EncodableValue ${api.name}::WrapError(std::string_view error_message) {
|
flutter::EncodableValue ${api.name}::WrapError(std::string_view error_message) {
|
||||||
\treturn flutter::EncodableValue(flutter::EncodableList{
|
\treturn flutter::EncodableValue(flutter::EncodableList{
|
||||||
@ -831,7 +830,7 @@ flutter::EncodableValue ${api.name}::WrapError(const FlutterError& error) {
|
|||||||
\t\terror.details()
|
\t\terror.details()
|
||||||
\t});
|
\t});
|
||||||
}''');
|
}''');
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _writeCodec(
|
void _writeCodec(
|
||||||
@ -842,12 +841,13 @@ flutter::EncodableValue ${api.name}::WrapError(const FlutterError& error) {
|
|||||||
) {
|
) {
|
||||||
assert(getCodecClasses(api, root).isNotEmpty);
|
assert(getCodecClasses(api, root).isNotEmpty);
|
||||||
final String codeSerializerName = _getCodecSerializerName(api);
|
final String codeSerializerName = _getCodecSerializerName(api);
|
||||||
|
indent.newln();
|
||||||
indent.writeln('$codeSerializerName::$codeSerializerName() {}');
|
indent.writeln('$codeSerializerName::$codeSerializerName() {}');
|
||||||
indent.write(
|
indent.write(
|
||||||
'flutter::EncodableValue $codeSerializerName::ReadValueOfType(uint8_t type, flutter::ByteStreamReader* stream) const ');
|
'flutter::EncodableValue $codeSerializerName::ReadValueOfType(uint8_t type, flutter::ByteStreamReader* stream) const ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.write('switch (type) ');
|
indent.write('switch (type) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
for (final EnumeratedClass customClass in getCodecClasses(api, root)) {
|
for (final EnumeratedClass customClass in getCodecClasses(api, root)) {
|
||||||
indent.write('case ${customClass.enumeration}:');
|
indent.write('case ${customClass.enumeration}:');
|
||||||
indent.writeScoped('', '', () {
|
indent.writeScoped('', '', () {
|
||||||
@ -862,17 +862,17 @@ flutter::EncodableValue ${api.name}::WrapError(const FlutterError& error) {
|
|||||||
}, addTrailingNewline: false);
|
}, addTrailingNewline: false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
indent.write(
|
indent.write(
|
||||||
'void $codeSerializerName::WriteValue(const flutter::EncodableValue& value, flutter::ByteStreamWriter* stream) const ');
|
'void $codeSerializerName::WriteValue(const flutter::EncodableValue& value, flutter::ByteStreamWriter* stream) const ');
|
||||||
indent.writeScoped('{', '}', () {
|
indent.writeScoped('{', '}', () {
|
||||||
indent.write(
|
indent.write(
|
||||||
'if (const flutter::CustomEncodableValue* custom_value = std::get_if<flutter::CustomEncodableValue>(&value)) ');
|
'if (const flutter::CustomEncodableValue* custom_value = std::get_if<flutter::CustomEncodableValue>(&value)) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
for (final EnumeratedClass customClass in getCodecClasses(api, root)) {
|
for (final EnumeratedClass customClass in getCodecClasses(api, root)) {
|
||||||
indent.write(
|
indent.write(
|
||||||
'if (custom_value->type() == typeid(${customClass.name})) ');
|
'if (custom_value->type() == typeid(${customClass.name})) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('stream->WriteByte(${customClass.enumeration});');
|
indent.writeln('stream->WriteByte(${customClass.enumeration});');
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'WriteValue(flutter::EncodableValue(std::any_cast<${customClass.name}>(*custom_value).ToEncodableList()), stream);');
|
'WriteValue(flutter::EncodableValue(std::any_cast<${customClass.name}>(*custom_value).ToEncodableList()), stream);');
|
||||||
@ -882,7 +882,7 @@ flutter::EncodableValue ${api.name}::WrapError(const FlutterError& error) {
|
|||||||
});
|
});
|
||||||
indent.writeln('$_defaultCodecSerializer::WriteValue(value, stream);');
|
indent.writeln('$_defaultCodecSerializer::WriteValue(value, stream);');
|
||||||
});
|
});
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _writeCppSourceClassField(CppOptions generatorOptions, Root root,
|
void _writeCppSourceClassField(CppOptions generatorOptions, Root root,
|
||||||
@ -919,7 +919,7 @@ flutter::EncodableValue ${api.name}::WrapError(const FlutterError& error) {
|
|||||||
indent.writeln(makeSetter(nonNullType));
|
indent.writeln(makeSetter(nonNullType));
|
||||||
}
|
}
|
||||||
|
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
|
|
||||||
String _wrapResponse(Indent indent, Root root, TypeDeclaration returnType,
|
String _wrapResponse(Indent indent, Root root, TypeDeclaration returnType,
|
||||||
|
@ -86,7 +86,7 @@ class DartGenerator extends StructuredGenerator<DartOptions> {
|
|||||||
indent.writeln(
|
indent.writeln(
|
||||||
'// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import',
|
'// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import',
|
||||||
);
|
);
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -96,7 +96,7 @@ class DartGenerator extends StructuredGenerator<DartOptions> {
|
|||||||
indent.writeln(
|
indent.writeln(
|
||||||
"import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List;",
|
"import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List;",
|
||||||
);
|
);
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
"import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer;");
|
"import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer;");
|
||||||
indent.writeln("import 'package:flutter/services.dart';");
|
indent.writeln("import 'package:flutter/services.dart';");
|
||||||
@ -105,11 +105,11 @@ class DartGenerator extends StructuredGenerator<DartOptions> {
|
|||||||
@override
|
@override
|
||||||
void writeEnum(
|
void writeEnum(
|
||||||
DartOptions generatorOptions, Root root, Indent indent, Enum anEnum) {
|
DartOptions generatorOptions, Root root, Indent indent, Enum anEnum) {
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
addDocumentationComments(
|
addDocumentationComments(
|
||||||
indent, anEnum.documentationComments, _docCommentSpec);
|
indent, anEnum.documentationComments, _docCommentSpec);
|
||||||
indent.write('enum ${anEnum.name} ');
|
indent.write('enum ${anEnum.name} ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
for (final EnumMember member in anEnum.members) {
|
for (final EnumMember member in anEnum.members) {
|
||||||
addDocumentationComments(
|
addDocumentationComments(
|
||||||
indent, member.documentationComments, _docCommentSpec);
|
indent, member.documentationComments, _docCommentSpec);
|
||||||
@ -126,25 +126,25 @@ class DartGenerator extends StructuredGenerator<DartOptions> {
|
|||||||
final Set<String> customEnumNames =
|
final Set<String> customEnumNames =
|
||||||
root.enums.map((Enum x) => x.name).toSet();
|
root.enums.map((Enum x) => x.name).toSet();
|
||||||
|
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
addDocumentationComments(
|
addDocumentationComments(
|
||||||
indent, klass.documentationComments, _docCommentSpec);
|
indent, klass.documentationComments, _docCommentSpec);
|
||||||
|
|
||||||
indent.write('class ${klass.name} ');
|
indent.write('class ${klass.name} ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
_writeConstructor(indent, klass);
|
_writeConstructor(indent, klass);
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
|
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
|
||||||
addDocumentationComments(
|
addDocumentationComments(
|
||||||
indent, field.documentationComments, _docCommentSpec);
|
indent, field.documentationComments, _docCommentSpec);
|
||||||
|
|
||||||
final String datatype = _addGenericTypesNullable(field.type);
|
final String datatype = _addGenericTypesNullable(field.type);
|
||||||
indent.writeln('$datatype ${field.name};');
|
indent.writeln('$datatype ${field.name};');
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
writeClassEncode(generatorOptions, root, indent, klass, customClassNames,
|
writeClassEncode(generatorOptions, root, indent, klass, customClassNames,
|
||||||
customEnumNames);
|
customEnumNames);
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
writeClassDecode(generatorOptions, root, indent, klass, customClassNames,
|
writeClassDecode(generatorOptions, root, indent, klass, customClassNames,
|
||||||
customEnumNames);
|
customEnumNames);
|
||||||
});
|
});
|
||||||
@ -152,7 +152,7 @@ class DartGenerator extends StructuredGenerator<DartOptions> {
|
|||||||
|
|
||||||
void _writeConstructor(Indent indent, Class klass) {
|
void _writeConstructor(Indent indent, Class klass) {
|
||||||
indent.write(klass.name);
|
indent.write(klass.name);
|
||||||
indent.scoped('({', '});', () {
|
indent.addScoped('({', '});', () {
|
||||||
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
|
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
|
||||||
final String required = field.type.isNullable ? '' : 'required ';
|
final String required = field.type.isNullable ? '' : 'required ';
|
||||||
indent.writeln('${required}this.${field.name},');
|
indent.writeln('${required}this.${field.name},');
|
||||||
@ -170,11 +170,11 @@ class DartGenerator extends StructuredGenerator<DartOptions> {
|
|||||||
Set<String> customEnumNames,
|
Set<String> customEnumNames,
|
||||||
) {
|
) {
|
||||||
indent.write('Object encode() ');
|
indent.write('Object encode() ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.write(
|
indent.write(
|
||||||
'return <Object?>',
|
'return <Object?>',
|
||||||
);
|
);
|
||||||
indent.scoped('[', '];', () {
|
indent.addScoped('[', '];', () {
|
||||||
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
|
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
|
||||||
final String conditional = field.type.isNullable ? '?' : '';
|
final String conditional = field.type.isNullable ? '?' : '';
|
||||||
if (customClassNames.contains(field.type.baseName)) {
|
if (customClassNames.contains(field.type.baseName)) {
|
||||||
@ -207,27 +207,25 @@ class DartGenerator extends StructuredGenerator<DartOptions> {
|
|||||||
if (customClassNames.contains(field.type.baseName)) {
|
if (customClassNames.contains(field.type.baseName)) {
|
||||||
final String nonNullValue =
|
final String nonNullValue =
|
||||||
'${field.type.baseName}.decode($resultAt! as List<Object?>)';
|
'${field.type.baseName}.decode($resultAt! as List<Object?>)';
|
||||||
indent.format(
|
if (field.type.isNullable) {
|
||||||
field.type.isNullable
|
indent.format('''
|
||||||
? '''
|
|
||||||
$resultAt != null
|
$resultAt != null
|
||||||
\t\t? $nonNullValue
|
\t\t? $nonNullValue
|
||||||
\t\t: null'''
|
\t\t: null''', leadingSpace: false, trailingNewline: false);
|
||||||
: nonNullValue,
|
} else {
|
||||||
leadingSpace: false,
|
indent.add(nonNullValue);
|
||||||
trailingNewline: false);
|
}
|
||||||
} else if (customEnumNames.contains(field.type.baseName)) {
|
} else if (customEnumNames.contains(field.type.baseName)) {
|
||||||
final String nonNullValue =
|
final String nonNullValue =
|
||||||
'${field.type.baseName}.values[$resultAt! as int]';
|
'${field.type.baseName}.values[$resultAt! as int]';
|
||||||
indent.format(
|
if (field.type.isNullable) {
|
||||||
field.type.isNullable
|
indent.format('''
|
||||||
? '''
|
|
||||||
$resultAt != null
|
$resultAt != null
|
||||||
\t\t? $nonNullValue
|
\t\t? $nonNullValue
|
||||||
\t\t: null'''
|
\t\t: null''', leadingSpace: false, trailingNewline: false);
|
||||||
: nonNullValue,
|
} else {
|
||||||
leadingSpace: false,
|
indent.add(nonNullValue);
|
||||||
trailingNewline: false);
|
}
|
||||||
} else if (field.type.typeArguments.isNotEmpty) {
|
} else if (field.type.typeArguments.isNotEmpty) {
|
||||||
final String genericType = _makeGenericTypeArguments(field.type);
|
final String genericType = _makeGenericTypeArguments(field.type);
|
||||||
final String castCall = _makeGenericCastCall(field.type);
|
final String castCall = _makeGenericCastCall(field.type);
|
||||||
@ -252,10 +250,10 @@ $resultAt != null
|
|||||||
indent.write(
|
indent.write(
|
||||||
'static ${klass.name} decode(Object result) ',
|
'static ${klass.name} decode(Object result) ',
|
||||||
);
|
);
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('result as List<Object?>;');
|
indent.writeln('result as List<Object?>;');
|
||||||
indent.write('return ${klass.name}');
|
indent.write('return ${klass.name}');
|
||||||
indent.scoped('(', ');', () {
|
indent.addScoped('(', ');', () {
|
||||||
enumerate(getFieldsInSerializationOrder(klass),
|
enumerate(getFieldsInSerializationOrder(klass),
|
||||||
(int index, final NamedType field) {
|
(int index, final NamedType field) {
|
||||||
indent.write('${field.name}: ');
|
indent.write('${field.name}: ');
|
||||||
@ -292,15 +290,15 @@ $resultAt != null
|
|||||||
codecName = _getCodecName(api);
|
codecName = _getCodecName(api);
|
||||||
_writeCodec(indent, codecName, api, root);
|
_writeCodec(indent, codecName, api, root);
|
||||||
}
|
}
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
addDocumentationComments(
|
addDocumentationComments(
|
||||||
indent, api.documentationComments, _docCommentSpec);
|
indent, api.documentationComments, _docCommentSpec);
|
||||||
|
|
||||||
indent.write('abstract class ${api.name} ');
|
indent.write('abstract class ${api.name} ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent
|
indent
|
||||||
.writeln('static const MessageCodec<Object?> codec = $codecName();');
|
.writeln('static const MessageCodec<Object?> codec = $codecName();');
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
for (final Method func in api.methods) {
|
for (final Method func in api.methods) {
|
||||||
addDocumentationComments(
|
addDocumentationComments(
|
||||||
indent, func.documentationComments, _docCommentSpec);
|
indent, func.documentationComments, _docCommentSpec);
|
||||||
@ -314,14 +312,14 @@ $resultAt != null
|
|||||||
_getArgumentName,
|
_getArgumentName,
|
||||||
);
|
);
|
||||||
indent.writeln('$returnType ${func.name}($argSignature);');
|
indent.writeln('$returnType ${func.name}($argSignature);');
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
indent.write(
|
indent.write(
|
||||||
'static void setup(${api.name}? api, {BinaryMessenger? binaryMessenger}) ');
|
'static void setup(${api.name}? api, {BinaryMessenger? binaryMessenger}) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
for (final Method func in api.methods) {
|
for (final Method func in api.methods) {
|
||||||
indent.write('');
|
indent.write('');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(',
|
'final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(',
|
||||||
);
|
);
|
||||||
@ -337,15 +335,15 @@ $resultAt != null
|
|||||||
final String messageHandlerSetter =
|
final String messageHandlerSetter =
|
||||||
isMockHandler ? 'setMockMessageHandler' : 'setMessageHandler';
|
isMockHandler ? 'setMockMessageHandler' : 'setMessageHandler';
|
||||||
indent.write('if (api == null) ');
|
indent.write('if (api == null) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('channel.$messageHandlerSetter(null);');
|
indent.writeln('channel.$messageHandlerSetter(null);');
|
||||||
}, addTrailingNewline: false);
|
}, addTrailingNewline: false);
|
||||||
indent.add(' else ');
|
indent.add(' else ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.write(
|
indent.write(
|
||||||
'channel.$messageHandlerSetter((Object? message) async ',
|
'channel.$messageHandlerSetter((Object? message) async ',
|
||||||
);
|
);
|
||||||
indent.scoped('{', '});', () {
|
indent.addScoped('{', '});', () {
|
||||||
final String returnType =
|
final String returnType =
|
||||||
_addGenericTypesNullable(func.returnType);
|
_addGenericTypesNullable(func.returnType);
|
||||||
final bool isAsync = func.isAsynchronous;
|
final bool isAsync = func.isAsynchronous;
|
||||||
@ -382,8 +380,9 @@ $resultAt != null
|
|||||||
'$leftHandSide = ($argsArray[$count] as $genericArgType?)${castCall.isEmpty ? '' : '?$castCall'};');
|
'$leftHandSide = ($argsArray[$count] as $genericArgType?)${castCall.isEmpty ? '' : '?$castCall'};');
|
||||||
}
|
}
|
||||||
if (!arg.type.isNullable) {
|
if (!arg.type.isNullable) {
|
||||||
|
indent.writeln('assert($argName != null,');
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
"assert($argName != null, 'Argument for $channelName was null, expected non-null $argType.');");
|
" 'Argument for $channelName was null, expected non-null $argType.');");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
final Iterable<String> argNames =
|
final Iterable<String> argNames =
|
||||||
@ -446,12 +445,12 @@ $resultAt != null
|
|||||||
codecName = _getCodecName(api);
|
codecName = _getCodecName(api);
|
||||||
_writeCodec(indent, codecName, api, root);
|
_writeCodec(indent, codecName, api, root);
|
||||||
}
|
}
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
bool first = true;
|
bool first = true;
|
||||||
addDocumentationComments(
|
addDocumentationComments(
|
||||||
indent, api.documentationComments, _docCommentSpec);
|
indent, api.documentationComments, _docCommentSpec);
|
||||||
indent.write('class ${api.name} ');
|
indent.write('class ${api.name} ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.format('''
|
indent.format('''
|
||||||
/// Constructor for [${api.name}]. The [binaryMessenger] named argument is
|
/// Constructor for [${api.name}]. The [binaryMessenger] named argument is
|
||||||
/// available for dependency injection. If it is left null, the default
|
/// available for dependency injection. If it is left null, the default
|
||||||
@ -463,10 +462,10 @@ final BinaryMessenger? _binaryMessenger;
|
|||||||
|
|
||||||
indent
|
indent
|
||||||
.writeln('static const MessageCodec<Object?> codec = $codecName();');
|
.writeln('static const MessageCodec<Object?> codec = $codecName();');
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
for (final Method func in api.methods) {
|
for (final Method func in api.methods) {
|
||||||
if (!first) {
|
if (!first) {
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
} else {
|
} else {
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
@ -494,7 +493,7 @@ final BinaryMessenger? _binaryMessenger;
|
|||||||
indent.write(
|
indent.write(
|
||||||
'Future<${_addGenericTypesNullable(func.returnType)}> ${func.name}($argSignature) async ',
|
'Future<${_addGenericTypesNullable(func.returnType)}> ${func.name}($argSignature) async ',
|
||||||
);
|
);
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
final String channelName = makeChannelName(api, func);
|
final String channelName = makeChannelName(api, func);
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(');
|
'final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(');
|
||||||
@ -585,7 +584,6 @@ if (replyList == null) {
|
|||||||
dartHostTestHandler: api.dartHostTestHandler,
|
dartHostTestHandler: api.dartHostTestHandler,
|
||||||
documentationComments: api.documentationComments,
|
documentationComments: api.documentationComments,
|
||||||
);
|
);
|
||||||
indent.writeln('');
|
|
||||||
writeFlutterApi(
|
writeFlutterApi(
|
||||||
generatorOptions,
|
generatorOptions,
|
||||||
root,
|
root,
|
||||||
@ -621,7 +619,7 @@ if (replyList == null) {
|
|||||||
"import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer;");
|
"import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer;");
|
||||||
indent.writeln("import 'package:flutter/services.dart';");
|
indent.writeln("import 'package:flutter/services.dart';");
|
||||||
indent.writeln("import 'package:flutter_test/flutter_test.dart';");
|
indent.writeln("import 'package:flutter_test/flutter_test.dart';");
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -642,33 +640,34 @@ String _getCodecName(Api api) => '_${api.name}Codec';
|
|||||||
void _writeCodec(Indent indent, String codecName, Api api, Root root) {
|
void _writeCodec(Indent indent, String codecName, Api api, Root root) {
|
||||||
assert(getCodecClasses(api, root).isNotEmpty);
|
assert(getCodecClasses(api, root).isNotEmpty);
|
||||||
final Iterable<EnumeratedClass> codecClasses = getCodecClasses(api, root);
|
final Iterable<EnumeratedClass> codecClasses = getCodecClasses(api, root);
|
||||||
|
indent.newln();
|
||||||
indent.write('class $codecName extends $_standardMessageCodec');
|
indent.write('class $codecName extends $_standardMessageCodec');
|
||||||
indent.scoped(' {', '}', () {
|
indent.addScoped(' {', '}', () {
|
||||||
indent.writeln('const $codecName();');
|
indent.writeln('const $codecName();');
|
||||||
indent.writeln('@override');
|
indent.writeln('@override');
|
||||||
indent.write('void writeValue(WriteBuffer buffer, Object? value) ');
|
indent.write('void writeValue(WriteBuffer buffer, Object? value) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
enumerate(codecClasses, (int index, final EnumeratedClass customClass) {
|
enumerate(codecClasses, (int index, final EnumeratedClass customClass) {
|
||||||
final String ifValue = 'if (value is ${customClass.name}) ';
|
final String ifValue = 'if (value is ${customClass.name}) ';
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
indent.write('');
|
indent.write('');
|
||||||
}
|
}
|
||||||
indent.add(ifValue);
|
indent.add(ifValue);
|
||||||
indent.scoped('{', '} else ', () {
|
indent.addScoped('{', '} else ', () {
|
||||||
indent.writeln('buffer.putUint8(${customClass.enumeration});');
|
indent.writeln('buffer.putUint8(${customClass.enumeration});');
|
||||||
indent.writeln('writeValue(buffer, value.encode());');
|
indent.writeln('writeValue(buffer, value.encode());');
|
||||||
}, addTrailingNewline: false);
|
}, addTrailingNewline: false);
|
||||||
});
|
});
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('super.writeValue(buffer, value);');
|
indent.writeln('super.writeValue(buffer, value);');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
indent.writeln('@override');
|
indent.writeln('@override');
|
||||||
indent.write('Object? readValueOfType(int type, ReadBuffer buffer) ');
|
indent.write('Object? readValueOfType(int type, ReadBuffer buffer) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.write('switch (type) ');
|
indent.write('switch (type) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
for (final EnumeratedClass customClass in codecClasses) {
|
for (final EnumeratedClass customClass in codecClasses) {
|
||||||
indent.write('case ${customClass.enumeration}: ');
|
indent.write('case ${customClass.enumeration}: ');
|
||||||
indent.writeScoped('', '', () {
|
indent.writeScoped('', '', () {
|
||||||
@ -677,7 +676,7 @@ void _writeCodec(Indent indent, String codecName, Api api, Root root) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
indent.writeln('default:');
|
indent.writeln('default:');
|
||||||
indent.scoped('', '', () {
|
indent.nest(1, () {
|
||||||
indent.writeln('return super.readValueOfType(type, buffer);');
|
indent.writeln('return super.readValueOfType(type, buffer);');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -9,7 +9,7 @@ import 'dart:mirrors';
|
|||||||
import 'ast.dart';
|
import 'ast.dart';
|
||||||
|
|
||||||
/// The current version of pigeon. This must match the version in pubspec.yaml.
|
/// The current version of pigeon. This must match the version in pubspec.yaml.
|
||||||
const String pigeonVersion = '7.0.0';
|
const String pigeonVersion = '7.0.1';
|
||||||
|
|
||||||
/// Read all the content from [stdin] to a String.
|
/// Read all the content from [stdin] to a String.
|
||||||
String readStdin() {
|
String readStdin() {
|
||||||
@ -83,7 +83,7 @@ class Indent {
|
|||||||
|
|
||||||
/// Scoped increase of the ident level. For the execution of [func] the
|
/// Scoped increase of the ident level. For the execution of [func] the
|
||||||
/// indentation will be incremented.
|
/// indentation will be incremented.
|
||||||
void scoped(
|
void addScoped(
|
||||||
String? begin,
|
String? begin,
|
||||||
String? end,
|
String? end,
|
||||||
Function func, {
|
Function func, {
|
||||||
@ -102,14 +102,14 @@ class Indent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Like `scoped` but writes the current indentation level.
|
/// Like `addScoped` but writes the current indentation level.
|
||||||
void writeScoped(
|
void writeScoped(
|
||||||
String? begin,
|
String? begin,
|
||||||
String end,
|
String end,
|
||||||
Function func, {
|
Function func, {
|
||||||
bool addTrailingNewline = true,
|
bool addTrailingNewline = true,
|
||||||
}) {
|
}) {
|
||||||
scoped(str() + (begin ?? ''), end, func,
|
addScoped(str() + (begin ?? ''), end, func,
|
||||||
addTrailingNewline: addTrailingNewline);
|
addTrailingNewline: addTrailingNewline);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,6 +144,13 @@ class Indent {
|
|||||||
void add(String text) {
|
void add(String text) {
|
||||||
_sink.write(text);
|
_sink.write(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Adds [lines] number of newlines.
|
||||||
|
void newln([int lines = 1]) {
|
||||||
|
for (; lines > 0; lines--) {
|
||||||
|
_sink.write(newline);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create the generated channel name for a [func] on a [api].
|
/// Create the generated channel name for a [func] on a [api].
|
||||||
|
@ -98,7 +98,7 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
|
|||||||
}
|
}
|
||||||
indent.writeln('// $generatedCodeWarning');
|
indent.writeln('// $generatedCodeWarning');
|
||||||
indent.writeln('// $seeAlsoWarning');
|
indent.writeln('// $seeAlsoWarning');
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -106,6 +106,7 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
|
|||||||
JavaOptions generatorOptions, Root root, Indent indent) {
|
JavaOptions generatorOptions, Root root, Indent indent) {
|
||||||
if (generatorOptions.package != null) {
|
if (generatorOptions.package != null) {
|
||||||
indent.writeln('package ${generatorOptions.package};');
|
indent.writeln('package ${generatorOptions.package};');
|
||||||
|
indent.newln();
|
||||||
}
|
}
|
||||||
indent.writeln('import android.util.Log;');
|
indent.writeln('import android.util.Log;');
|
||||||
indent.writeln('import androidx.annotation.NonNull;');
|
indent.writeln('import androidx.annotation.NonNull;');
|
||||||
@ -116,13 +117,13 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
|
|||||||
indent.writeln('import io.flutter.plugin.common.StandardMessageCodec;');
|
indent.writeln('import io.flutter.plugin.common.StandardMessageCodec;');
|
||||||
indent.writeln('import java.io.ByteArrayOutputStream;');
|
indent.writeln('import java.io.ByteArrayOutputStream;');
|
||||||
indent.writeln('import java.nio.ByteBuffer;');
|
indent.writeln('import java.nio.ByteBuffer;');
|
||||||
indent.writeln('import java.util.Arrays;');
|
|
||||||
indent.writeln('import java.util.ArrayList;');
|
indent.writeln('import java.util.ArrayList;');
|
||||||
|
indent.writeln('import java.util.Arrays;');
|
||||||
indent.writeln('import java.util.Collections;');
|
indent.writeln('import java.util.Collections;');
|
||||||
|
indent.writeln('import java.util.HashMap;');
|
||||||
indent.writeln('import java.util.List;');
|
indent.writeln('import java.util.List;');
|
||||||
indent.writeln('import java.util.Map;');
|
indent.writeln('import java.util.Map;');
|
||||||
indent.writeln('import java.util.HashMap;');
|
indent.newln();
|
||||||
indent.addln('');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -149,22 +150,23 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
|
|||||||
.toUpperCase();
|
.toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
addDocumentationComments(
|
addDocumentationComments(
|
||||||
indent, anEnum.documentationComments, _docCommentSpec);
|
indent, anEnum.documentationComments, _docCommentSpec);
|
||||||
|
|
||||||
indent.write('public enum ${anEnum.name} ');
|
indent.write('public enum ${anEnum.name} ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
enumerate(anEnum.members, (int index, final EnumMember member) {
|
enumerate(anEnum.members, (int index, final EnumMember member) {
|
||||||
addDocumentationComments(
|
addDocumentationComments(
|
||||||
indent, member.documentationComments, _docCommentSpec);
|
indent, member.documentationComments, _docCommentSpec);
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'${camelToSnake(member.name)}($index)${index == anEnum.members.length - 1 ? ';' : ','}');
|
'${camelToSnake(member.name)}($index)${index == anEnum.members.length - 1 ? ';' : ','}');
|
||||||
});
|
});
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
indent.writeln('private final int index;');
|
indent.writeln('private final int index;');
|
||||||
|
indent.newln();
|
||||||
indent.write('private ${anEnum.name}(final int index) ');
|
indent.write('private ${anEnum.name}(final int index) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('this.index = index;');
|
indent.writeln('this.index = index;');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -181,24 +183,25 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
|
|||||||
const List<String> generatedMessages = <String>[
|
const List<String> generatedMessages = <String>[
|
||||||
' Generated class from Pigeon that represents data sent in messages.'
|
' Generated class from Pigeon that represents data sent in messages.'
|
||||||
];
|
];
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
addDocumentationComments(
|
addDocumentationComments(
|
||||||
indent, klass.documentationComments, _docCommentSpec,
|
indent, klass.documentationComments, _docCommentSpec,
|
||||||
generatorComments: generatedMessages);
|
generatorComments: generatedMessages);
|
||||||
|
|
||||||
indent.write('public static final class ${klass.name} ');
|
indent.write('public static final class ${klass.name} ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
|
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
|
||||||
_writeClassField(generatorOptions, root, indent, field);
|
_writeClassField(generatorOptions, root, indent, field);
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getFieldsInSerializationOrder(klass)
|
if (getFieldsInSerializationOrder(klass)
|
||||||
.map((NamedType e) => !e.type.isNullable)
|
.map((NamedType e) => !e.type.isNullable)
|
||||||
.any((bool e) => e)) {
|
.any((bool e) => e)) {
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'${_docCommentPrefix}Constructor is private to enforce null safety; use Builder.$_docCommentSuffix');
|
'$_docCommentPrefix Constructor is private to enforce null safety; use Builder.$_docCommentSuffix');
|
||||||
indent.writeln('private ${klass.name}() {}');
|
indent.writeln('private ${klass.name}() {}');
|
||||||
|
indent.newln();
|
||||||
}
|
}
|
||||||
|
|
||||||
_writeClassBuilder(generatorOptions, root, indent, klass);
|
_writeClassBuilder(generatorOptions, root, indent, klass);
|
||||||
@ -219,8 +222,13 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
|
|||||||
|
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'private $nullability ${hostDatatype.datatype} ${field.name};');
|
'private $nullability ${hostDatatype.datatype} ${field.name};');
|
||||||
indent.writeln(
|
indent.newln();
|
||||||
'public $nullability ${hostDatatype.datatype} ${_makeGetter(field)}() { return ${field.name}; }');
|
indent.write(
|
||||||
|
'public $nullability ${hostDatatype.datatype} ${_makeGetter(field)}() ');
|
||||||
|
indent.addScoped('{', '}', () {
|
||||||
|
indent.writeln('return ${field.name};');
|
||||||
|
});
|
||||||
|
indent.newln();
|
||||||
indent.writeScoped(
|
indent.writeScoped(
|
||||||
'public void ${_makeSetter(field)}($nullability ${hostDatatype.datatype} setterArg) {',
|
'public void ${_makeSetter(field)}($nullability ${hostDatatype.datatype} setterArg) {',
|
||||||
'}', () {
|
'}', () {
|
||||||
@ -241,7 +249,7 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
|
|||||||
Class klass,
|
Class klass,
|
||||||
) {
|
) {
|
||||||
indent.write('public static final class Builder ');
|
indent.write('public static final class Builder ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
|
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
|
||||||
final HostDatatype hostDatatype = getFieldHostDatatype(
|
final HostDatatype hostDatatype = getFieldHostDatatype(
|
||||||
field,
|
field,
|
||||||
@ -250,8 +258,10 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
|
|||||||
(TypeDeclaration x) => _javaTypeForBuiltinDartType(x));
|
(TypeDeclaration x) => _javaTypeForBuiltinDartType(x));
|
||||||
final String nullability =
|
final String nullability =
|
||||||
field.type.isNullable ? '@Nullable' : '@NonNull';
|
field.type.isNullable ? '@Nullable' : '@NonNull';
|
||||||
|
indent.newln();
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'private @Nullable ${hostDatatype.datatype} ${field.name};');
|
'private @Nullable ${hostDatatype.datatype} ${field.name};');
|
||||||
|
indent.newln();
|
||||||
indent.writeScoped(
|
indent.writeScoped(
|
||||||
'public @NonNull Builder ${_makeSetter(field)}($nullability ${hostDatatype.datatype} setterArg) {',
|
'public @NonNull Builder ${_makeSetter(field)}($nullability ${hostDatatype.datatype} setterArg) {',
|
||||||
'}', () {
|
'}', () {
|
||||||
@ -259,8 +269,9 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
|
|||||||
indent.writeln('return this;');
|
indent.writeln('return this;');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
indent.newln();
|
||||||
indent.write('public @NonNull ${klass.name} build() ');
|
indent.write('public @NonNull ${klass.name} build() ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
const String returnVal = 'pigeonReturn';
|
const String returnVal = 'pigeonReturn';
|
||||||
indent.writeln('${klass.name} $returnVal = new ${klass.name}();');
|
indent.writeln('${klass.name} $returnVal = new ${klass.name}();');
|
||||||
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
|
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
|
||||||
@ -280,8 +291,10 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
|
|||||||
Set<String> customClassNames,
|
Set<String> customClassNames,
|
||||||
Set<String> customEnumNames,
|
Set<String> customEnumNames,
|
||||||
) {
|
) {
|
||||||
indent.write('@NonNull ArrayList<Object> toList() ');
|
indent.newln();
|
||||||
indent.scoped('{', '}', () {
|
indent.writeln('@NonNull');
|
||||||
|
indent.write('ArrayList<Object> toList() ');
|
||||||
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'ArrayList<Object> toListResult = new ArrayList<Object>(${klass.fields.length});');
|
'ArrayList<Object> toListResult = new ArrayList<Object>(${klass.fields.length});');
|
||||||
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
|
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
|
||||||
@ -316,9 +329,10 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
|
|||||||
Set<String> customClassNames,
|
Set<String> customClassNames,
|
||||||
Set<String> customEnumNames,
|
Set<String> customEnumNames,
|
||||||
) {
|
) {
|
||||||
|
indent.newln();
|
||||||
indent.write(
|
indent.write(
|
||||||
'static @NonNull ${klass.name} fromList(@NonNull ArrayList<Object> list) ');
|
'static @NonNull ${klass.name} fromList(@NonNull ArrayList<Object> list) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
const String result = 'pigeonResult';
|
const String result = 'pigeonResult';
|
||||||
indent.writeln('${klass.name} $result = new ${klass.name}();');
|
indent.writeln('${klass.name} $result = new ${klass.name}();');
|
||||||
enumerate(getFieldsInSerializationOrder(klass),
|
enumerate(getFieldsInSerializationOrder(klass),
|
||||||
@ -365,26 +379,28 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
|
|||||||
generatorComments: generatedMessages);
|
generatorComments: generatedMessages);
|
||||||
|
|
||||||
indent.write('public static final class ${api.name} ');
|
indent.write('public static final class ${api.name} ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('private final BinaryMessenger binaryMessenger;');
|
indent.writeln('private final BinaryMessenger binaryMessenger;');
|
||||||
|
indent.newln();
|
||||||
indent.write('public ${api.name}(BinaryMessenger argBinaryMessenger) ');
|
indent.write('public ${api.name}(BinaryMessenger argBinaryMessenger) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('this.binaryMessenger = argBinaryMessenger;');
|
indent.writeln('this.binaryMessenger = argBinaryMessenger;');
|
||||||
});
|
});
|
||||||
|
indent.newln();
|
||||||
indent.write('/** Public interface for sending reply. */ ');
|
indent.write('/** Public interface for sending reply. */ ');
|
||||||
indent.write('public interface Reply<T> ');
|
indent.write('public interface Reply<T> ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('void reply(T reply);');
|
indent.writeln('void reply(T reply);');
|
||||||
});
|
});
|
||||||
final String codecName = _getCodecName(api);
|
final String codecName = _getCodecName(api);
|
||||||
indent.writeln('/** The codec used by ${api.name}. */');
|
indent.writeln('/** The codec used by ${api.name}. */');
|
||||||
indent.write('static MessageCodec<Object> getCodec() ');
|
indent.write('static MessageCodec<Object> getCodec() ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.write('return ');
|
indent.write('return ');
|
||||||
if (getCodecClasses(api, root).isNotEmpty) {
|
if (getCodecClasses(api, root).isNotEmpty) {
|
||||||
indent.writeln('$codecName.INSTANCE;');
|
indent.addln('$codecName.INSTANCE;');
|
||||||
} else {
|
} else {
|
||||||
indent.writeln('new $_standardMessageCodec();');
|
indent.addln('new $_standardMessageCodec();');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -418,20 +434,23 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
|
|||||||
indent.write(
|
indent.write(
|
||||||
'public void ${func.name}($argsSignature, Reply<$returnType> callback) ');
|
'public void ${func.name}($argsSignature, Reply<$returnType> callback) ');
|
||||||
}
|
}
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
const String channel = 'channel';
|
const String channel = 'channel';
|
||||||
indent.writeln('BasicMessageChannel<Object> $channel =');
|
indent.writeln('BasicMessageChannel<Object> $channel =');
|
||||||
indent.inc();
|
indent.nest(2, () {
|
||||||
indent.inc();
|
indent.writeln('new BasicMessageChannel<>(');
|
||||||
indent.writeln(
|
indent.nest(2, () {
|
||||||
'new BasicMessageChannel<>(binaryMessenger, "$channelName", getCodec());');
|
indent.writeln('binaryMessenger, "$channelName", getCodec());');
|
||||||
indent.dec();
|
});
|
||||||
indent.dec();
|
});
|
||||||
indent.write('$channel.send($sendArgument, channelReply -> ');
|
indent.writeln('$channel.send(');
|
||||||
|
indent.nest(2, () {
|
||||||
|
indent.writeln('$sendArgument,');
|
||||||
|
indent.write('channelReply -> ');
|
||||||
if (func.returnType.isVoid) {
|
if (func.returnType.isVoid) {
|
||||||
indent.addln('callback.reply(null));');
|
indent.addln('callback.reply(null));');
|
||||||
} else {
|
} else {
|
||||||
indent.scoped('{', '});', () {
|
indent.addScoped('{', '});', () {
|
||||||
const String output = 'output';
|
const String output = 'output';
|
||||||
indent.writeln('@SuppressWarnings("ConstantConditions")');
|
indent.writeln('@SuppressWarnings("ConstantConditions")');
|
||||||
if (func.returnType.baseName == 'int') {
|
if (func.returnType.baseName == 'int') {
|
||||||
@ -445,6 +464,7 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -454,7 +474,7 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
|
|||||||
if (root.apis.any((Api api) =>
|
if (root.apis.any((Api api) =>
|
||||||
api.location == ApiLocation.host &&
|
api.location == ApiLocation.host &&
|
||||||
api.methods.any((Method it) => it.isAsynchronous))) {
|
api.methods.any((Method it) => it.isAsynchronous))) {
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
_writeResultInterface(indent);
|
_writeResultInterface(indent);
|
||||||
}
|
}
|
||||||
super.writeApis(generatorOptions, root, indent);
|
super.writeApis(generatorOptions, root, indent);
|
||||||
@ -480,20 +500,20 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
|
|||||||
generatorComments: generatedMessages);
|
generatorComments: generatedMessages);
|
||||||
|
|
||||||
indent.write('public interface ${api.name} ');
|
indent.write('public interface ${api.name} ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
for (final Method method in api.methods) {
|
for (final Method method in api.methods) {
|
||||||
_writeInterfaceMethod(generatorOptions, root, indent, api, method);
|
_writeInterfaceMethod(generatorOptions, root, indent, api, method);
|
||||||
}
|
}
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
final String codecName = _getCodecName(api);
|
final String codecName = _getCodecName(api);
|
||||||
indent.writeln('/** The codec used by ${api.name}. */');
|
indent.writeln('/** The codec used by ${api.name}. */');
|
||||||
indent.write('static MessageCodec<Object> getCodec() ');
|
indent.write('static MessageCodec<Object> getCodec() ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.write('return ');
|
indent.write('return ');
|
||||||
if (getCodecClasses(api, root).isNotEmpty) {
|
if (getCodecClasses(api, root).isNotEmpty) {
|
||||||
indent.write('$codecName.INSTANCE;');
|
indent.addln('$codecName.INSTANCE;');
|
||||||
} else {
|
} else {
|
||||||
indent.write('new $_standardMessageCodec();');
|
indent.addln('new $_standardMessageCodec();');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -501,7 +521,7 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
|
|||||||
'${_docCommentPrefix}Sets up an instance of `${api.name}` to handle messages through the `binaryMessenger`.$_docCommentSuffix');
|
'${_docCommentPrefix}Sets up an instance of `${api.name}` to handle messages through the `binaryMessenger`.$_docCommentSuffix');
|
||||||
indent.write(
|
indent.write(
|
||||||
'static void setup(BinaryMessenger binaryMessenger, ${api.name} api) ');
|
'static void setup(BinaryMessenger binaryMessenger, ${api.name} api) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
for (final Method method in api.methods) {
|
for (final Method method in api.methods) {
|
||||||
_writeMethodSetup(generatorOptions, root, indent, api, method);
|
_writeMethodSetup(generatorOptions, root, indent, api, method);
|
||||||
}
|
}
|
||||||
@ -514,9 +534,12 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
|
|||||||
/// int add(int x, int y);
|
/// int add(int x, int y);
|
||||||
void _writeInterfaceMethod(JavaOptions generatorOptions, Root root,
|
void _writeInterfaceMethod(JavaOptions generatorOptions, Root root,
|
||||||
Indent indent, Api api, final Method method) {
|
Indent indent, Api api, final Method method) {
|
||||||
|
final String nullableType = method.isAsynchronous
|
||||||
|
? ''
|
||||||
|
: _nullabilityAnnotationFromType(method.returnType);
|
||||||
final String returnType = method.isAsynchronous
|
final String returnType = method.isAsynchronous
|
||||||
? 'void'
|
? 'void'
|
||||||
: _nullsafeJavaTypeForDartType(method.returnType);
|
: _javaTypeForDartType(method.returnType);
|
||||||
final List<String> argSignature = <String>[];
|
final List<String> argSignature = <String>[];
|
||||||
if (method.arguments.isNotEmpty) {
|
if (method.arguments.isNotEmpty) {
|
||||||
final Iterable<String> argTypes = method.arguments
|
final Iterable<String> argTypes = method.arguments
|
||||||
@ -534,9 +557,15 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
|
|||||||
: _javaTypeForDartType(method.returnType);
|
: _javaTypeForDartType(method.returnType);
|
||||||
argSignature.add('Result<$resultType> result');
|
argSignature.add('Result<$resultType> result');
|
||||||
}
|
}
|
||||||
|
if (method.documentationComments.isNotEmpty) {
|
||||||
addDocumentationComments(
|
addDocumentationComments(
|
||||||
indent, method.documentationComments, _docCommentSpec);
|
indent, method.documentationComments, _docCommentSpec);
|
||||||
|
} else {
|
||||||
|
indent.newln();
|
||||||
|
}
|
||||||
|
if (nullableType != '') {
|
||||||
|
indent.writeln(nullableType);
|
||||||
|
}
|
||||||
indent.writeln('$returnType ${method.name}(${argSignature.join(', ')});');
|
indent.writeln('$returnType ${method.name}(${argSignature.join(', ')});');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -547,7 +576,7 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
|
|||||||
Api api, final Method method) {
|
Api api, final Method method) {
|
||||||
final String channelName = makeChannelName(api, method);
|
final String channelName = makeChannelName(api, method);
|
||||||
indent.write('');
|
indent.write('');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
String? taskQueue;
|
String? taskQueue;
|
||||||
if (method.taskQueueType != TaskQueueType.serial) {
|
if (method.taskQueueType != TaskQueueType.serial) {
|
||||||
taskQueue = 'taskQueue';
|
taskQueue = 'taskQueue';
|
||||||
@ -555,27 +584,29 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
|
|||||||
'BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue();');
|
'BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue();');
|
||||||
}
|
}
|
||||||
indent.writeln('BasicMessageChannel<Object> channel =');
|
indent.writeln('BasicMessageChannel<Object> channel =');
|
||||||
indent.inc();
|
indent.nest(2, () {
|
||||||
indent.inc();
|
indent.writeln('new BasicMessageChannel<>(');
|
||||||
indent.write(
|
indent.nest(2, () {
|
||||||
'new BasicMessageChannel<>(binaryMessenger, "$channelName", getCodec()');
|
indent.write('binaryMessenger, "$channelName", getCodec()');
|
||||||
if (taskQueue != null) {
|
if (taskQueue != null) {
|
||||||
indent.addln(', $taskQueue);');
|
indent.addln(', $taskQueue);');
|
||||||
} else {
|
} else {
|
||||||
indent.addln(');');
|
indent.addln(');');
|
||||||
}
|
}
|
||||||
indent.dec();
|
});
|
||||||
indent.dec();
|
});
|
||||||
indent.write('if (api != null) ');
|
indent.write('if (api != null) ');
|
||||||
indent.scoped('{', '} else {', () {
|
indent.addScoped('{', '} else {', () {
|
||||||
indent.write('channel.setMessageHandler((message, reply) -> ');
|
indent.writeln('channel.setMessageHandler(');
|
||||||
indent.scoped('{', '});', () {
|
indent.nest(2, () {
|
||||||
|
indent.write('(message, reply) -> ');
|
||||||
|
indent.addScoped('{', '});', () {
|
||||||
final String returnType = method.returnType.isVoid
|
final String returnType = method.returnType.isVoid
|
||||||
? 'Void'
|
? 'Void'
|
||||||
: _javaTypeForDartType(method.returnType);
|
: _javaTypeForDartType(method.returnType);
|
||||||
indent.writeln('ArrayList wrapped = new ArrayList<>();');
|
indent.writeln('ArrayList wrapped = new ArrayList<>();');
|
||||||
indent.write('try ');
|
indent.write('try ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
final List<String> methodArgument = <String>[];
|
final List<String> methodArgument = <String>[];
|
||||||
if (method.arguments.isNotEmpty) {
|
if (method.arguments.isNotEmpty) {
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
@ -601,7 +632,7 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
|
|||||||
indent.writeln('$argType $argName = $accessor;');
|
indent.writeln('$argType $argName = $accessor;');
|
||||||
if (!arg.type.isNullable) {
|
if (!arg.type.isNullable) {
|
||||||
indent.write('if ($argName == null) ');
|
indent.write('if ($argName == null) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'throw new NullPointerException("$argName unexpectedly null.");');
|
'throw new NullPointerException("$argName unexpectedly null.");');
|
||||||
});
|
});
|
||||||
@ -614,16 +645,18 @@ class JavaGenerator extends StructuredGenerator<JavaOptions> {
|
|||||||
method.returnType.isVoid ? 'null' : 'result';
|
method.returnType.isVoid ? 'null' : 'result';
|
||||||
const String resultName = 'resultCallback';
|
const String resultName = 'resultCallback';
|
||||||
indent.format('''
|
indent.format('''
|
||||||
Result<$returnType> $resultName = new Result<$returnType>() {
|
Result<$returnType> $resultName =
|
||||||
\tpublic void success($returnType result) {
|
\t\tnew Result<$returnType>() {
|
||||||
\t\twrapped.add(0, $resultValue);
|
\t\t\tpublic void success($returnType result) {
|
||||||
\t\treply.reply(wrapped);
|
\t\t\t\twrapped.add(0, $resultValue);
|
||||||
\t}
|
\t\t\t\treply.reply(wrapped);
|
||||||
\tpublic void error(Throwable error) {
|
\t\t\t}
|
||||||
\t\tArrayList<Object> wrappedError = wrapError(error);
|
|
||||||
\t\treply.reply(wrappedError);
|
\t\t\tpublic void error(Throwable error) {
|
||||||
\t}
|
\t\t\t\tArrayList<Object> wrappedError = wrapError(error);
|
||||||
};
|
\t\t\t\treply.reply(wrappedError);
|
||||||
|
\t\t\t}
|
||||||
|
\t\t};
|
||||||
''');
|
''');
|
||||||
methodArgument.add(resultName);
|
methodArgument.add(resultName);
|
||||||
}
|
}
|
||||||
@ -638,9 +671,9 @@ Result<$returnType> $resultName = new Result<$returnType>() {
|
|||||||
indent.writeln('$returnType output = $call;');
|
indent.writeln('$returnType output = $call;');
|
||||||
indent.writeln('wrapped.add(0, output);');
|
indent.writeln('wrapped.add(0, output);');
|
||||||
}
|
}
|
||||||
});
|
}, addTrailingNewline: false);
|
||||||
indent.write('catch (Error | RuntimeException exception) ');
|
indent.add(' catch (Error | RuntimeException exception) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'ArrayList<Object> wrappedError = wrapError(exception);');
|
'ArrayList<Object> wrappedError = wrapError(exception);');
|
||||||
if (method.isAsynchronous) {
|
if (method.isAsynchronous) {
|
||||||
@ -654,7 +687,8 @@ Result<$returnType> $resultName = new Result<$returnType>() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
indent.scoped(null, '}', () {
|
});
|
||||||
|
indent.addScoped(null, '}', () {
|
||||||
indent.writeln('channel.setMessageHandler(null);');
|
indent.writeln('channel.setMessageHandler(null);');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -667,18 +701,21 @@ Result<$returnType> $resultName = new Result<$returnType>() {
|
|||||||
assert(getCodecClasses(api, root).isNotEmpty);
|
assert(getCodecClasses(api, root).isNotEmpty);
|
||||||
final Iterable<EnumeratedClass> codecClasses = getCodecClasses(api, root);
|
final Iterable<EnumeratedClass> codecClasses = getCodecClasses(api, root);
|
||||||
final String codecName = _getCodecName(api);
|
final String codecName = _getCodecName(api);
|
||||||
|
indent.newln();
|
||||||
indent.write(
|
indent.write(
|
||||||
'private static class $codecName extends $_standardMessageCodec ');
|
'private static class $codecName extends $_standardMessageCodec ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'public static final $codecName INSTANCE = new $codecName();');
|
'public static final $codecName INSTANCE = new $codecName();');
|
||||||
|
indent.newln();
|
||||||
indent.writeln('private $codecName() {}');
|
indent.writeln('private $codecName() {}');
|
||||||
|
indent.newln();
|
||||||
indent.writeln('@Override');
|
indent.writeln('@Override');
|
||||||
indent.write(
|
indent.write(
|
||||||
'protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) ');
|
'protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.write('switch (type) ');
|
indent.write('switch (type) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
for (final EnumeratedClass customClass in codecClasses) {
|
for (final EnumeratedClass customClass in codecClasses) {
|
||||||
indent.write('case (byte) ${customClass.enumeration}: ');
|
indent.write('case (byte) ${customClass.enumeration}: ');
|
||||||
indent.writeScoped('', '', () {
|
indent.writeScoped('', '', () {
|
||||||
@ -687,46 +724,55 @@ Result<$returnType> $resultName = new Result<$returnType>() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
indent.write('default:');
|
indent.write('default:');
|
||||||
indent.writeScoped('', '', () {
|
indent.addScoped('', '', () {
|
||||||
indent.writeln('return super.readValueOfType(type, buffer);');
|
indent.writeln('return super.readValueOfType(type, buffer);');
|
||||||
|
}, addTrailingNewline: false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
indent.newln();
|
||||||
indent.writeln('@Override');
|
indent.writeln('@Override');
|
||||||
indent.write(
|
indent.write(
|
||||||
'protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) ');
|
'protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) ');
|
||||||
indent.writeScoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
|
bool firstClass = true;
|
||||||
for (final EnumeratedClass customClass in codecClasses) {
|
for (final EnumeratedClass customClass in codecClasses) {
|
||||||
indent.write('if (value instanceof ${customClass.name}) ');
|
if (firstClass) {
|
||||||
indent.scoped('{', '} else ', () {
|
indent.write('');
|
||||||
|
firstClass = false;
|
||||||
|
}
|
||||||
|
indent.add('if (value instanceof ${customClass.name}) ');
|
||||||
|
indent.addScoped('{', '} else ', () {
|
||||||
indent.writeln('stream.write(${customClass.enumeration});');
|
indent.writeln('stream.write(${customClass.enumeration});');
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'writeValue(stream, ((${customClass.name}) value).toList());');
|
'writeValue(stream, ((${customClass.name}) value).toList());');
|
||||||
});
|
}, addTrailingNewline: false);
|
||||||
}
|
}
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('super.writeValue(stream, value);');
|
indent.writeln('super.writeValue(stream, value);');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _writeResultInterface(Indent indent) {
|
void _writeResultInterface(Indent indent) {
|
||||||
indent.write('public interface Result<T> ');
|
indent.write('public interface Result<T> ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('void success(T result);');
|
indent.writeln('void success(T result);');
|
||||||
|
indent.newln();
|
||||||
indent.writeln('void error(Throwable error);');
|
indent.writeln('void error(Throwable error);');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _writeWrapError(Indent indent) {
|
void _writeWrapError(Indent indent) {
|
||||||
indent.format('''
|
indent.format('''
|
||||||
@NonNull private static ArrayList<Object> wrapError(@NonNull Throwable exception) {
|
@NonNull
|
||||||
|
private static ArrayList<Object> wrapError(@NonNull Throwable exception) {
|
||||||
\tArrayList<Object> errorList = new ArrayList<>(3);
|
\tArrayList<Object> errorList = new ArrayList<>(3);
|
||||||
\terrorList.add(exception.toString());
|
\terrorList.add(exception.toString());
|
||||||
\terrorList.add(exception.getClass().getSimpleName());
|
\terrorList.add(exception.getClass().getSimpleName());
|
||||||
\terrorList.add("Cause: " + exception.getCause() + ", Stacktrace: " + Log.getStackTraceString(exception));
|
\terrorList.add(
|
||||||
|
\t\t"Cause: " + exception.getCause() + ", Stacktrace: " + Log.getStackTraceString(exception));
|
||||||
\treturn errorList;
|
\treturn errorList;
|
||||||
}''');
|
}''');
|
||||||
}
|
}
|
||||||
@ -815,9 +861,12 @@ String _javaTypeForDartType(TypeDeclaration type) {
|
|||||||
return _javaTypeForBuiltinDartType(type) ?? type.baseName;
|
return _javaTypeForBuiltinDartType(type) ?? type.baseName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String _nullabilityAnnotationFromType(TypeDeclaration type) {
|
||||||
|
return type.isVoid ? '' : (type.isNullable ? '@Nullable ' : '@NonNull ');
|
||||||
|
}
|
||||||
|
|
||||||
String _nullsafeJavaTypeForDartType(TypeDeclaration type) {
|
String _nullsafeJavaTypeForDartType(TypeDeclaration type) {
|
||||||
final String nullSafe =
|
final String nullSafe = _nullabilityAnnotationFromType(type);
|
||||||
type.isVoid ? '' : (type.isNullable ? '@Nullable ' : '@NonNull ');
|
|
||||||
return '$nullSafe${_javaTypeForDartType(type)}';
|
return '$nullSafe${_javaTypeForDartType(type)}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,11 +83,11 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
|
|||||||
@override
|
@override
|
||||||
void writeFileImports(
|
void writeFileImports(
|
||||||
KotlinOptions generatorOptions, Root root, Indent indent) {
|
KotlinOptions generatorOptions, Root root, Indent indent) {
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
if (generatorOptions.package != null) {
|
if (generatorOptions.package != null) {
|
||||||
indent.writeln('package ${generatorOptions.package}');
|
indent.writeln('package ${generatorOptions.package}');
|
||||||
}
|
}
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
indent.writeln('import android.util.Log');
|
indent.writeln('import android.util.Log');
|
||||||
indent.writeln('import io.flutter.plugin.common.BasicMessageChannel');
|
indent.writeln('import io.flutter.plugin.common.BasicMessageChannel');
|
||||||
indent.writeln('import io.flutter.plugin.common.BinaryMessenger');
|
indent.writeln('import io.flutter.plugin.common.BinaryMessenger');
|
||||||
@ -100,11 +100,11 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
|
|||||||
@override
|
@override
|
||||||
void writeEnum(
|
void writeEnum(
|
||||||
KotlinOptions generatorOptions, Root root, Indent indent, Enum anEnum) {
|
KotlinOptions generatorOptions, Root root, Indent indent, Enum anEnum) {
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
addDocumentationComments(
|
addDocumentationComments(
|
||||||
indent, anEnum.documentationComments, _docCommentSpec);
|
indent, anEnum.documentationComments, _docCommentSpec);
|
||||||
indent.write('enum class ${anEnum.name}(val raw: Int) ');
|
indent.write('enum class ${anEnum.name}(val raw: Int) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
enumerate(anEnum.members, (int index, final EnumMember member) {
|
enumerate(anEnum.members, (int index, final EnumMember member) {
|
||||||
addDocumentationComments(
|
addDocumentationComments(
|
||||||
indent, member.documentationComments, _docCommentSpec);
|
indent, member.documentationComments, _docCommentSpec);
|
||||||
@ -116,11 +116,11 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
indent.write('companion object ');
|
indent.write('companion object ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.write('fun ofRaw(raw: Int): ${anEnum.name}? ');
|
indent.write('fun ofRaw(raw: Int): ${anEnum.name}? ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('return values().firstOrNull { it.raw == raw }');
|
indent.writeln('return values().firstOrNull { it.raw == raw }');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -138,24 +138,24 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
|
|||||||
const List<String> generatedMessages = <String>[
|
const List<String> generatedMessages = <String>[
|
||||||
' Generated class from Pigeon that represents data sent in messages.'
|
' Generated class from Pigeon that represents data sent in messages.'
|
||||||
];
|
];
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
addDocumentationComments(
|
addDocumentationComments(
|
||||||
indent, klass.documentationComments, _docCommentSpec,
|
indent, klass.documentationComments, _docCommentSpec,
|
||||||
generatorComments: generatedMessages);
|
generatorComments: generatedMessages);
|
||||||
|
|
||||||
indent.write('data class ${klass.name} ');
|
indent.write('data class ${klass.name} ');
|
||||||
indent.scoped('(', '', () {
|
indent.addScoped('(', '', () {
|
||||||
for (final NamedType element in getFieldsInSerializationOrder(klass)) {
|
for (final NamedType element in getFieldsInSerializationOrder(klass)) {
|
||||||
_writeClassField(indent, element);
|
_writeClassField(indent, element);
|
||||||
if (getFieldsInSerializationOrder(klass).last != element) {
|
if (getFieldsInSerializationOrder(klass).last != element) {
|
||||||
indent.addln(',');
|
indent.addln(',');
|
||||||
} else {
|
} else {
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
indent.scoped(') {', '}', () {
|
indent.addScoped(') {', '}', () {
|
||||||
writeClassDecode(generatorOptions, root, indent, klass, customClassNames,
|
writeClassDecode(generatorOptions, root, indent, klass, customClassNames,
|
||||||
customEnumNames);
|
customEnumNames);
|
||||||
writeClassEncode(generatorOptions, root, indent, klass, customClassNames,
|
writeClassEncode(generatorOptions, root, indent, klass, customClassNames,
|
||||||
@ -173,9 +173,9 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
|
|||||||
Set<String> customEnumNames,
|
Set<String> customEnumNames,
|
||||||
) {
|
) {
|
||||||
indent.write('fun toList(): List<Any?> ');
|
indent.write('fun toList(): List<Any?> ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.write('return listOf<Any?>');
|
indent.write('return listOf<Any?>');
|
||||||
indent.scoped('(', ')', () {
|
indent.addScoped('(', ')', () {
|
||||||
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
|
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
|
||||||
final HostDatatype hostDatatype = _getHostDatatype(root, field);
|
final HostDatatype hostDatatype = _getHostDatatype(root, field);
|
||||||
String toWriteValue = '';
|
String toWriteValue = '';
|
||||||
@ -207,11 +207,11 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
|
|||||||
final String className = klass.name;
|
final String className = klass.name;
|
||||||
|
|
||||||
indent.write('companion object ');
|
indent.write('companion object ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('@Suppress("UNCHECKED_CAST")');
|
indent.writeln('@Suppress("UNCHECKED_CAST")');
|
||||||
indent.write('fun fromList(list: List<Any?>): $className ');
|
indent.write('fun fromList(list: List<Any?>): $className ');
|
||||||
|
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
enumerate(getFieldsInSerializationOrder(klass),
|
enumerate(getFieldsInSerializationOrder(klass),
|
||||||
(int index, final NamedType field) {
|
(int index, final NamedType field) {
|
||||||
final HostDatatype hostDatatype = _getHostDatatype(root, field);
|
final HostDatatype hostDatatype = _getHostDatatype(root, field);
|
||||||
@ -229,14 +229,14 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
|
|||||||
customClassNames.contains(field.type.baseName)) {
|
customClassNames.contains(field.type.baseName)) {
|
||||||
indent.write('val ${field.name}: $fieldType? = ');
|
indent.write('val ${field.name}: $fieldType? = ');
|
||||||
indent.add('($listValue as? List<Any?>)?.let ');
|
indent.add('($listValue as? List<Any?>)?.let ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('$fieldType.fromList(it)');
|
indent.writeln('$fieldType.fromList(it)');
|
||||||
});
|
});
|
||||||
} else if (!hostDatatype.isBuiltin &&
|
} else if (!hostDatatype.isBuiltin &&
|
||||||
customEnumNames.contains(field.type.baseName)) {
|
customEnumNames.contains(field.type.baseName)) {
|
||||||
indent.write('val ${field.name}: $fieldType? = ');
|
indent.write('val ${field.name}: $fieldType? = ');
|
||||||
indent.add('($listValue as? Int)?.let ');
|
indent.add('($listValue as? Int)?.let ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('$fieldType.ofRaw(it)');
|
indent.writeln('$fieldType.ofRaw(it)');
|
||||||
});
|
});
|
||||||
} else if (isInt) {
|
} else if (isInt) {
|
||||||
@ -290,7 +290,7 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
|
|||||||
if (root.apis.any((Api api) =>
|
if (root.apis.any((Api api) =>
|
||||||
api.location == ApiLocation.host &&
|
api.location == ApiLocation.host &&
|
||||||
api.methods.any((Method it) => it.isAsynchronous))) {
|
api.methods.any((Method it) => it.isAsynchronous))) {
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
super.writeApis(generatorOptions, root, indent);
|
super.writeApis(generatorOptions, root, indent);
|
||||||
}
|
}
|
||||||
@ -323,12 +323,12 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
|
|||||||
indent.writeln('@Suppress("UNCHECKED_CAST")');
|
indent.writeln('@Suppress("UNCHECKED_CAST")');
|
||||||
indent
|
indent
|
||||||
.write('class $apiName(private val binaryMessenger: BinaryMessenger) ');
|
.write('class $apiName(private val binaryMessenger: BinaryMessenger) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.write('companion object ');
|
indent.write('companion object ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('/** The codec used by $apiName. */');
|
indent.writeln('/** The codec used by $apiName. */');
|
||||||
indent.write('val codec: MessageCodec<Any?> by lazy ');
|
indent.write('val codec: MessageCodec<Any?> by lazy ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
if (isCustomCodec) {
|
if (isCustomCodec) {
|
||||||
indent.writeln(_getCodecName(api));
|
indent.writeln(_getCodecName(api));
|
||||||
} else {
|
} else {
|
||||||
@ -366,18 +366,18 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
|
|||||||
'fun ${func.name}($argsSignature, callback: ($returnType) -> Unit) ');
|
'fun ${func.name}($argsSignature, callback: ($returnType) -> Unit) ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
const String channel = 'channel';
|
const String channel = 'channel';
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'val $channel = BasicMessageChannel<Any?>(binaryMessenger, "$channelName", codec)');
|
'val $channel = BasicMessageChannel<Any?>(binaryMessenger, "$channelName", codec)');
|
||||||
indent.write('$channel.send($sendArgument) ');
|
indent.write('$channel.send($sendArgument) ');
|
||||||
if (func.returnType.isVoid) {
|
if (func.returnType.isVoid) {
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('callback()');
|
indent.writeln('callback()');
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
final String forceUnwrap = func.returnType.isNullable ? '?' : '';
|
final String forceUnwrap = func.returnType.isNullable ? '?' : '';
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('val result = it as$forceUnwrap $returnType');
|
indent.writeln('val result = it as$forceUnwrap $returnType');
|
||||||
indent.writeln('callback(result)');
|
indent.writeln('callback(result)');
|
||||||
});
|
});
|
||||||
@ -418,7 +418,7 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
|
|||||||
generatorComments: generatedMessages);
|
generatorComments: generatedMessages);
|
||||||
|
|
||||||
indent.write('interface $apiName ');
|
indent.write('interface $apiName ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
for (final Method method in api.methods) {
|
for (final Method method in api.methods) {
|
||||||
final List<String> argSignature = <String>[];
|
final List<String> argSignature = <String>[];
|
||||||
if (method.arguments.isNotEmpty) {
|
if (method.arguments.isNotEmpty) {
|
||||||
@ -450,12 +450,12 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
indent.write('companion object ');
|
indent.write('companion object ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('/** The codec used by $apiName. */');
|
indent.writeln('/** The codec used by $apiName. */');
|
||||||
indent.write('val codec: MessageCodec<Any?> by lazy ');
|
indent.write('val codec: MessageCodec<Any?> by lazy ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
if (isCustomCodec) {
|
if (isCustomCodec) {
|
||||||
indent.writeln(_getCodecName(api));
|
indent.writeln(_getCodecName(api));
|
||||||
} else {
|
} else {
|
||||||
@ -467,10 +467,10 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
|
|||||||
indent.writeln('@Suppress("UNCHECKED_CAST")');
|
indent.writeln('@Suppress("UNCHECKED_CAST")');
|
||||||
indent.write(
|
indent.write(
|
||||||
'fun setUp(binaryMessenger: BinaryMessenger, api: $apiName?) ');
|
'fun setUp(binaryMessenger: BinaryMessenger, api: $apiName?) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
for (final Method method in api.methods) {
|
for (final Method method in api.methods) {
|
||||||
indent.write('run ');
|
indent.write('run ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
String? taskQueue;
|
String? taskQueue;
|
||||||
if (method.taskQueueType != TaskQueueType.serial) {
|
if (method.taskQueueType != TaskQueueType.serial) {
|
||||||
taskQueue = 'taskQueue';
|
taskQueue = 'taskQueue';
|
||||||
@ -490,15 +490,15 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
indent.write('if (api != null) ');
|
indent.write('if (api != null) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
final String messageVarName =
|
final String messageVarName =
|
||||||
method.arguments.isNotEmpty ? 'message' : '_';
|
method.arguments.isNotEmpty ? 'message' : '_';
|
||||||
|
|
||||||
indent.write('channel.setMessageHandler ');
|
indent.write('channel.setMessageHandler ');
|
||||||
indent.scoped('{ $messageVarName, reply ->', '}', () {
|
indent.addScoped('{ $messageVarName, reply ->', '}', () {
|
||||||
indent.writeln('var wrapped = listOf<Any?>()');
|
indent.writeln('var wrapped = listOf<Any?>()');
|
||||||
indent.write('try ');
|
indent.write('try ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
final List<String> methodArgument = <String>[];
|
final List<String> methodArgument = <String>[];
|
||||||
if (method.arguments.isNotEmpty) {
|
if (method.arguments.isNotEmpty) {
|
||||||
indent.writeln('val args = message as List<Any?>');
|
indent.writeln('val args = message as List<Any?>');
|
||||||
@ -516,7 +516,7 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
|
|||||||
indent.write('$call ');
|
indent.write('$call ');
|
||||||
final String resultValue =
|
final String resultValue =
|
||||||
method.returnType.isVoid ? 'null' : 'it';
|
method.returnType.isVoid ? 'null' : 'it';
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('reply.reply(wrapResult($resultValue))');
|
indent.writeln('reply.reply(wrapResult($resultValue))');
|
||||||
});
|
});
|
||||||
} else if (method.returnType.isVoid) {
|
} else if (method.returnType.isVoid) {
|
||||||
@ -527,7 +527,7 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
|
|||||||
}
|
}
|
||||||
}, addTrailingNewline: false);
|
}, addTrailingNewline: false);
|
||||||
indent.add(' catch (exception: Error) ');
|
indent.add(' catch (exception: Error) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('wrapped = wrapError(exception)');
|
indent.writeln('wrapped = wrapError(exception)');
|
||||||
if (method.isAsynchronous) {
|
if (method.isAsynchronous) {
|
||||||
indent.writeln('reply.reply(wrapped)');
|
indent.writeln('reply.reply(wrapped)');
|
||||||
@ -538,7 +538,7 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, addTrailingNewline: false);
|
}, addTrailingNewline: false);
|
||||||
indent.scoped(' else {', '}', () {
|
indent.addScoped(' else {', '}', () {
|
||||||
indent.writeln('channel.setMessageHandler(null)');
|
indent.writeln('channel.setMessageHandler(null)');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -557,17 +557,17 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
|
|||||||
final String codecName = _getCodecName(api);
|
final String codecName = _getCodecName(api);
|
||||||
indent.writeln('@Suppress("UNCHECKED_CAST")');
|
indent.writeln('@Suppress("UNCHECKED_CAST")');
|
||||||
indent.write('private object $codecName : StandardMessageCodec() ');
|
indent.write('private object $codecName : StandardMessageCodec() ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.write(
|
indent.write(
|
||||||
'override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? ');
|
'override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.write('return when (type) ');
|
indent.write('return when (type) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
for (final EnumeratedClass customClass in codecClasses) {
|
for (final EnumeratedClass customClass in codecClasses) {
|
||||||
indent.write('${customClass.enumeration}.toByte() -> ');
|
indent.write('${customClass.enumeration}.toByte() -> ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.write('return (readValue(buffer) as? List<Any?>)?.let ');
|
indent.write('return (readValue(buffer) as? List<Any?>)?.let ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('${customClass.name}.fromList(it)');
|
indent.writeln('${customClass.name}.fromList(it)');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -580,10 +580,10 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
|
|||||||
'override fun writeValue(stream: ByteArrayOutputStream, value: Any?) ');
|
'override fun writeValue(stream: ByteArrayOutputStream, value: Any?) ');
|
||||||
indent.writeScoped('{', '}', () {
|
indent.writeScoped('{', '}', () {
|
||||||
indent.write('when (value) ');
|
indent.write('when (value) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
for (final EnumeratedClass customClass in codecClasses) {
|
for (final EnumeratedClass customClass in codecClasses) {
|
||||||
indent.write('is ${customClass.name} -> ');
|
indent.write('is ${customClass.name} -> ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('stream.write(${customClass.enumeration})');
|
indent.writeln('stream.write(${customClass.enumeration})');
|
||||||
indent.writeln('writeValue(stream, value.toList())');
|
indent.writeln('writeValue(stream, value.toList())');
|
||||||
});
|
});
|
||||||
@ -592,23 +592,23 @@ class KotlinGenerator extends StructuredGenerator<KotlinOptions> {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _writeWrapResult(Indent indent) {
|
void _writeWrapResult(Indent indent) {
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
indent.write('private fun wrapResult(result: Any?): List<Any?> ');
|
indent.write('private fun wrapResult(result: Any?): List<Any?> ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('return listOf(result)');
|
indent.writeln('return listOf(result)');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _writeWrapError(Indent indent) {
|
void _writeWrapError(Indent indent) {
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
indent.write('private fun wrapError(exception: Throwable): List<Any> ');
|
indent.write('private fun wrapError(exception: Throwable): List<Any> ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.write('return ');
|
indent.write('return ');
|
||||||
indent.scoped('listOf<Any>(', ')', () {
|
indent.addScoped('listOf<Any>(', ')', () {
|
||||||
indent.writeln('exception.javaClass.simpleName,');
|
indent.writeln('exception.javaClass.simpleName,');
|
||||||
indent.writeln('exception.toString(),');
|
indent.writeln('exception.toString(),');
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
|
@ -96,20 +96,20 @@ class ObjcHeaderGenerator extends StructuredGenerator<ObjcOptions> {
|
|||||||
}
|
}
|
||||||
indent.writeln('// $generatedCodeWarning');
|
indent.writeln('// $generatedCodeWarning');
|
||||||
indent.writeln('// $seeAlsoWarning');
|
indent.writeln('// $seeAlsoWarning');
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void writeFileImports(
|
void writeFileImports(
|
||||||
ObjcOptions generatorOptions, Root root, Indent indent) {
|
ObjcOptions generatorOptions, Root root, Indent indent) {
|
||||||
indent.writeln('#import <Foundation/Foundation.h>');
|
indent.writeln('#import <Foundation/Foundation.h>');
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
|
|
||||||
indent.writeln('@protocol FlutterBinaryMessenger;');
|
indent.writeln('@protocol FlutterBinaryMessenger;');
|
||||||
indent.writeln('@protocol FlutterMessageCodec;');
|
indent.writeln('@protocol FlutterMessageCodec;');
|
||||||
indent.writeln('@class FlutterError;');
|
indent.writeln('@class FlutterError;');
|
||||||
indent.writeln('@class FlutterStandardTypedData;');
|
indent.writeln('@class FlutterStandardTypedData;');
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
indent.writeln('NS_ASSUME_NONNULL_BEGIN');
|
indent.writeln('NS_ASSUME_NONNULL_BEGIN');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,12 +117,12 @@ class ObjcHeaderGenerator extends StructuredGenerator<ObjcOptions> {
|
|||||||
void writeEnum(
|
void writeEnum(
|
||||||
ObjcOptions generatorOptions, Root root, Indent indent, Enum anEnum) {
|
ObjcOptions generatorOptions, Root root, Indent indent, Enum anEnum) {
|
||||||
final String enumName = _className(generatorOptions.prefix, anEnum.name);
|
final String enumName = _className(generatorOptions.prefix, anEnum.name);
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
addDocumentationComments(
|
addDocumentationComments(
|
||||||
indent, anEnum.documentationComments, _docCommentSpec);
|
indent, anEnum.documentationComments, _docCommentSpec);
|
||||||
|
|
||||||
indent.write('typedef NS_ENUM(NSUInteger, $enumName) ');
|
indent.write('typedef NS_ENUM(NSUInteger, $enumName) ');
|
||||||
indent.scoped('{', '};', () {
|
indent.addScoped('{', '};', () {
|
||||||
enumerate(anEnum.members, (int index, final EnumMember member) {
|
enumerate(anEnum.members, (int index, final EnumMember member) {
|
||||||
addDocumentationComments(
|
addDocumentationComments(
|
||||||
indent, member.documentationComments, _docCommentSpec);
|
indent, member.documentationComments, _docCommentSpec);
|
||||||
@ -136,12 +136,12 @@ class ObjcHeaderGenerator extends StructuredGenerator<ObjcOptions> {
|
|||||||
@override
|
@override
|
||||||
void writeDataClasses(
|
void writeDataClasses(
|
||||||
ObjcOptions generatorOptions, Root root, Indent indent) {
|
ObjcOptions generatorOptions, Root root, Indent indent) {
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
for (final Class klass in root.classes) {
|
for (final Class klass in root.classes) {
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'@class ${_className(generatorOptions.prefix, klass.name)};');
|
'@class ${_className(generatorOptions.prefix, klass.name)};');
|
||||||
}
|
}
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
super.writeDataClasses(generatorOptions, root, indent);
|
super.writeDataClasses(generatorOptions, root, indent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,7 +192,7 @@ class ObjcHeaderGenerator extends StructuredGenerator<ObjcOptions> {
|
|||||||
'@property(nonatomic, $propertyType$nullability) ${hostDatatype.datatype} ${field.name};');
|
'@property(nonatomic, $propertyType$nullability) ${hostDatatype.datatype} ${field.name};');
|
||||||
}
|
}
|
||||||
indent.writeln('@end');
|
indent.writeln('@end');
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -232,7 +232,7 @@ class ObjcHeaderGenerator extends StructuredGenerator<ObjcOptions> {
|
|||||||
'$_docCommentPrefix The codec used by ${_className(generatorOptions.prefix, api.name)}.');
|
'$_docCommentPrefix The codec used by ${_className(generatorOptions.prefix, api.name)}.');
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'NSObject<FlutterMessageCodec> *${_getCodecGetterName(generatorOptions.prefix, api.name)}(void);');
|
'NSObject<FlutterMessageCodec> *${_getCodecGetterName(generatorOptions.prefix, api.name)}(void);');
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
final String apiName = _className(generatorOptions.prefix, api.name);
|
final String apiName = _className(generatorOptions.prefix, api.name);
|
||||||
addDocumentationComments(
|
addDocumentationComments(
|
||||||
indent, api.documentationComments, _docCommentSpec);
|
indent, api.documentationComments, _docCommentSpec);
|
||||||
@ -257,7 +257,7 @@ class ObjcHeaderGenerator extends StructuredGenerator<ObjcOptions> {
|
|||||||
)};');
|
)};');
|
||||||
}
|
}
|
||||||
indent.writeln('@end');
|
indent.writeln('@end');
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -271,7 +271,7 @@ class ObjcHeaderGenerator extends StructuredGenerator<ObjcOptions> {
|
|||||||
'$_docCommentPrefix The codec used by ${_className(generatorOptions.prefix, api.name)}.');
|
'$_docCommentPrefix The codec used by ${_className(generatorOptions.prefix, api.name)}.');
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'NSObject<FlutterMessageCodec> *${_getCodecGetterName(generatorOptions.prefix, api.name)}(void);');
|
'NSObject<FlutterMessageCodec> *${_getCodecGetterName(generatorOptions.prefix, api.name)}(void);');
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
final String apiName = _className(generatorOptions.prefix, api.name);
|
final String apiName = _className(generatorOptions.prefix, api.name);
|
||||||
addDocumentationComments(
|
addDocumentationComments(
|
||||||
indent, api.documentationComments, _docCommentSpec);
|
indent, api.documentationComments, _docCommentSpec);
|
||||||
@ -322,10 +322,10 @@ class ObjcHeaderGenerator extends StructuredGenerator<ObjcOptions> {
|
|||||||
indent.writeln('$signature;');
|
indent.writeln('$signature;');
|
||||||
}
|
}
|
||||||
indent.writeln('@end');
|
indent.writeln('@end');
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'extern void ${apiName}Setup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<$apiName> *_Nullable api);');
|
'extern void ${apiName}Setup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<$apiName> *_Nullable api);');
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -342,7 +342,7 @@ class ObjcSourceGenerator extends StructuredGenerator<ObjcOptions> {
|
|||||||
}
|
}
|
||||||
indent.writeln('// $generatedCodeWarning');
|
indent.writeln('// $generatedCodeWarning');
|
||||||
indent.writeln('// $seeAlsoWarning');
|
indent.writeln('// $seeAlsoWarning');
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -350,24 +350,23 @@ class ObjcSourceGenerator extends StructuredGenerator<ObjcOptions> {
|
|||||||
ObjcOptions generatorOptions, Root root, Indent indent) {
|
ObjcOptions generatorOptions, Root root, Indent indent) {
|
||||||
indent.writeln('#import "${generatorOptions.headerIncludePath}"');
|
indent.writeln('#import "${generatorOptions.headerIncludePath}"');
|
||||||
indent.writeln('#import <Flutter/Flutter.h>');
|
indent.writeln('#import <Flutter/Flutter.h>');
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
|
|
||||||
indent.writeln('#if !__has_feature(objc_arc)');
|
indent.writeln('#if !__has_feature(objc_arc)');
|
||||||
indent.writeln('#error File requires ARC to be enabled.');
|
indent.writeln('#error File requires ARC to be enabled.');
|
||||||
indent.writeln('#endif');
|
indent.writeln('#endif');
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void writeDataClasses(
|
void writeDataClasses(
|
||||||
ObjcOptions generatorOptions, Root root, Indent indent) {
|
ObjcOptions generatorOptions, Root root, Indent indent) {
|
||||||
_writeObjcSourceHelperFunctions(indent);
|
_writeObjcSourceHelperFunctions(indent);
|
||||||
indent.addln('');
|
|
||||||
|
|
||||||
for (final Class klass in root.classes) {
|
for (final Class klass in root.classes) {
|
||||||
_writeObjcSourceDataClassExtension(generatorOptions, indent, klass);
|
_writeObjcSourceDataClassExtension(generatorOptions, indent, klass);
|
||||||
}
|
}
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
super.writeDataClasses(generatorOptions, root, indent);
|
super.writeDataClasses(generatorOptions, root, indent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,7 +387,7 @@ class ObjcSourceGenerator extends StructuredGenerator<ObjcOptions> {
|
|||||||
writeClassEncode(generatorOptions, root, indent, klass, customClassNames,
|
writeClassEncode(generatorOptions, root, indent, klass, customClassNames,
|
||||||
customEnumNames);
|
customEnumNames);
|
||||||
indent.writeln('@end');
|
indent.writeln('@end');
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -401,9 +400,9 @@ class ObjcSourceGenerator extends StructuredGenerator<ObjcOptions> {
|
|||||||
Set<String> customEnumNames,
|
Set<String> customEnumNames,
|
||||||
) {
|
) {
|
||||||
indent.write('- (NSArray *)toList ');
|
indent.write('- (NSArray *)toList ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.write('return');
|
indent.write('return');
|
||||||
indent.scoped(' @[', '];', () {
|
indent.addScoped(' @[', '];', () {
|
||||||
for (final NamedType field in klass.fields) {
|
for (final NamedType field in klass.fields) {
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'${_arrayValue(customClassNames, customEnumNames, field)},');
|
'${_arrayValue(customClassNames, customEnumNames, field)},');
|
||||||
@ -423,7 +422,7 @@ class ObjcSourceGenerator extends StructuredGenerator<ObjcOptions> {
|
|||||||
) {
|
) {
|
||||||
final String className = _className(generatorOptions.prefix, klass.name);
|
final String className = _className(generatorOptions.prefix, klass.name);
|
||||||
indent.write('+ ($className *)fromList:(NSArray *)list ');
|
indent.write('+ ($className *)fromList:(NSArray *)list ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
const String resultName = 'pigeonResult';
|
const String resultName = 'pigeonResult';
|
||||||
indent.writeln('$className *$resultName = [[$className alloc] init];');
|
indent.writeln('$className *$resultName = [[$className alloc] init];');
|
||||||
enumerate(getFieldsInSerializationOrder(klass),
|
enumerate(getFieldsInSerializationOrder(klass),
|
||||||
@ -442,8 +441,10 @@ class ObjcSourceGenerator extends StructuredGenerator<ObjcOptions> {
|
|||||||
indent.writeln('return $resultName;');
|
indent.writeln('return $resultName;');
|
||||||
});
|
});
|
||||||
|
|
||||||
indent.writeln(
|
indent.write('+ (nullable $className *)nullableFromList:(NSArray *)list ');
|
||||||
'+ (nullable $className *)nullableFromList:(NSArray *)list { return (list) ? [$className fromList:list] : nil; }');
|
indent.addScoped('{', '}', () {
|
||||||
|
indent.writeln('return (list) ? [$className fromList:list] : nil;');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _writeCodecAndGetter(
|
void _writeCodecAndGetter(
|
||||||
@ -451,10 +452,10 @@ class ObjcSourceGenerator extends StructuredGenerator<ObjcOptions> {
|
|||||||
final String codecName = _getCodecName(generatorOptions.prefix, api.name);
|
final String codecName = _getCodecName(generatorOptions.prefix, api.name);
|
||||||
if (getCodecClasses(api, root).isNotEmpty) {
|
if (getCodecClasses(api, root).isNotEmpty) {
|
||||||
_writeCodec(indent, codecName, generatorOptions, api, root);
|
_writeCodec(indent, codecName, generatorOptions, api, root);
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
_writeCodecGetter(indent, codecName, generatorOptions, api, root);
|
_writeCodecGetter(indent, codecName, generatorOptions, api, root);
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -470,15 +471,15 @@ class ObjcSourceGenerator extends StructuredGenerator<ObjcOptions> {
|
|||||||
_writeCodecAndGetter(generatorOptions, root, indent, api);
|
_writeCodecAndGetter(generatorOptions, root, indent, api);
|
||||||
|
|
||||||
_writeExtension(indent, apiName);
|
_writeExtension(indent, apiName);
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
indent.writeln('@implementation $apiName');
|
indent.writeln('@implementation $apiName');
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
_writeInitializer(indent);
|
_writeInitializer(indent);
|
||||||
for (final Method func in api.methods) {
|
for (final Method func in api.methods) {
|
||||||
_writeMethod(generatorOptions, root, indent, api, func);
|
_writeMethod(generatorOptions, root, indent, api, func);
|
||||||
}
|
}
|
||||||
indent.writeln('@end');
|
indent.writeln('@end');
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -496,13 +497,12 @@ class ObjcSourceGenerator extends StructuredGenerator<ObjcOptions> {
|
|||||||
const String channelName = 'channel';
|
const String channelName = 'channel';
|
||||||
indent.write(
|
indent.write(
|
||||||
'void ${apiName}Setup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<$apiName> *api) ');
|
'void ${apiName}Setup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<$apiName> *api) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
for (final Method func in api.methods) {
|
for (final Method func in api.methods) {
|
||||||
indent.write('');
|
|
||||||
addDocumentationComments(
|
addDocumentationComments(
|
||||||
indent, func.documentationComments, _docCommentSpec);
|
indent, func.documentationComments, _docCommentSpec);
|
||||||
|
|
||||||
indent.scoped('{', '}', () {
|
indent.writeScoped('{', '}', () {
|
||||||
String? taskQueue;
|
String? taskQueue;
|
||||||
if (func.taskQueueType != TaskQueueType.serial) {
|
if (func.taskQueueType != TaskQueueType.serial) {
|
||||||
taskQueue = 'taskQueue';
|
taskQueue = 'taskQueue';
|
||||||
@ -512,12 +512,12 @@ class ObjcSourceGenerator extends StructuredGenerator<ObjcOptions> {
|
|||||||
_writeChannelAllocation(
|
_writeChannelAllocation(
|
||||||
generatorOptions, indent, api, func, channelName, taskQueue);
|
generatorOptions, indent, api, func, channelName, taskQueue);
|
||||||
indent.write('if (api) ');
|
indent.write('if (api) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
_writeChannelApiBinding(
|
_writeChannelApiBinding(
|
||||||
generatorOptions, root, indent, apiName, func, channelName);
|
generatorOptions, root, indent, apiName, func, channelName);
|
||||||
});
|
}, addTrailingNewline: false);
|
||||||
indent.write('else ');
|
indent.add(' else ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('[$channelName setMessageHandler:nil];');
|
indent.writeln('[$channelName setMessageHandler:nil];');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -595,7 +595,7 @@ class ObjcSourceGenerator extends StructuredGenerator<ObjcOptions> {
|
|||||||
'NSCAssert([api respondsToSelector:@selector($selector)], @"$apiName api (%@) doesn\'t respond to @selector($selector)", api);');
|
'NSCAssert([api respondsToSelector:@selector($selector)], @"$apiName api (%@) doesn\'t respond to @selector($selector)", api);');
|
||||||
indent.write(
|
indent.write(
|
||||||
'[$channel setMessageHandler:^(id _Nullable message, FlutterReply callback) ');
|
'[$channel setMessageHandler:^(id _Nullable message, FlutterReply callback) ');
|
||||||
indent.scoped('{', '}];', () {
|
indent.addScoped('{', '}];', () {
|
||||||
final _ObjcPtr returnType =
|
final _ObjcPtr returnType =
|
||||||
_objcTypeForDartType(generatorOptions.prefix, func.returnType);
|
_objcTypeForDartType(generatorOptions.prefix, func.returnType);
|
||||||
final Iterable<String> selectorComponents =
|
final Iterable<String> selectorComponents =
|
||||||
@ -624,29 +624,32 @@ class ObjcSourceGenerator extends StructuredGenerator<ObjcOptions> {
|
|||||||
void _writeChannelAllocation(ObjcOptions generatorOptions, Indent indent,
|
void _writeChannelAllocation(ObjcOptions generatorOptions, Indent indent,
|
||||||
Api api, Method func, String varName, String? taskQueue) {
|
Api api, Method func, String varName, String? taskQueue) {
|
||||||
indent.writeln('FlutterBasicMessageChannel *$varName =');
|
indent.writeln('FlutterBasicMessageChannel *$varName =');
|
||||||
indent.inc();
|
indent.nest(1, () {
|
||||||
indent.writeln('[[FlutterBasicMessageChannel alloc]');
|
indent.writeln('[[FlutterBasicMessageChannel alloc]');
|
||||||
indent.inc();
|
indent.nest(1, () {
|
||||||
indent.writeln('initWithName:@"${makeChannelName(api, func)}"');
|
indent.writeln('initWithName:@"${makeChannelName(api, func)}"');
|
||||||
indent.writeln('binaryMessenger:binaryMessenger');
|
indent.writeln('binaryMessenger:binaryMessenger');
|
||||||
indent.write('codec:');
|
indent.write('codec:');
|
||||||
indent.add('${_getCodecGetterName(generatorOptions.prefix, api.name)}()');
|
indent
|
||||||
|
.add('${_getCodecGetterName(generatorOptions.prefix, api.name)}()');
|
||||||
|
|
||||||
if (taskQueue != null) {
|
if (taskQueue != null) {
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
indent.addln('taskQueue:$taskQueue];');
|
indent.addln('taskQueue:$taskQueue];');
|
||||||
} else {
|
} else {
|
||||||
indent.addln('];');
|
indent.addln('];');
|
||||||
}
|
}
|
||||||
indent.dec();
|
});
|
||||||
indent.dec();
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _writeObjcSourceHelperFunctions(Indent indent) {
|
void _writeObjcSourceHelperFunctions(Indent indent) {
|
||||||
indent.format('''
|
indent.format('''
|
||||||
static NSArray *wrapResult(id result, FlutterError *error) {
|
static NSArray *wrapResult(id result, FlutterError *error) {
|
||||||
\tif (error) {
|
\tif (error) {
|
||||||
\t\treturn @[ error.code ?: [NSNull null], error.message ?: [NSNull null], error.details ?: [NSNull null] ];
|
\t\treturn @[
|
||||||
|
\t\t\terror.code ?: [NSNull null], error.message ?: [NSNull null], error.details ?: [NSNull null]
|
||||||
|
\t\t];
|
||||||
\t}
|
\t}
|
||||||
\treturn @[ result ?: [NSNull null] ];
|
\treturn @[ result ?: [NSNull null] ];
|
||||||
}''');
|
}''');
|
||||||
@ -658,20 +661,19 @@ static id GetNullableObject(NSDictionary* dict, id key) {
|
|||||||
static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) {
|
static id GetNullableObjectAtIndex(NSArray *array, NSInteger key) {
|
||||||
\tid result = array[key];
|
\tid result = array[key];
|
||||||
\treturn (result == [NSNull null]) ? nil : result;
|
\treturn (result == [NSNull null]) ? nil : result;
|
||||||
}
|
}''');
|
||||||
''');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _writeObjcSourceDataClassExtension(
|
void _writeObjcSourceDataClassExtension(
|
||||||
ObjcOptions languageOptions, Indent indent, Class klass) {
|
ObjcOptions languageOptions, Indent indent, Class klass) {
|
||||||
final String className = _className(languageOptions.prefix, klass.name);
|
final String className = _className(languageOptions.prefix, klass.name);
|
||||||
|
indent.newln();
|
||||||
indent.writeln('@interface $className ()');
|
indent.writeln('@interface $className ()');
|
||||||
indent.writeln('+ ($className *)fromList:(NSArray *)list;');
|
indent.writeln('+ ($className *)fromList:(NSArray *)list;');
|
||||||
indent
|
indent
|
||||||
.writeln('+ (nullable $className *)nullableFromList:(NSArray *)list;');
|
.writeln('+ (nullable $className *)nullableFromList:(NSArray *)list;');
|
||||||
indent.writeln('- (NSArray *)toList;');
|
indent.writeln('- (NSArray *)toList;');
|
||||||
indent.writeln('@end');
|
indent.writeln('@end');
|
||||||
indent.writeln('');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _writeObjcSourceClassInitializer(
|
void _writeObjcSourceClassInitializer(
|
||||||
@ -715,10 +717,10 @@ static id GetNullableObjectAtIndex(NSArray* array, NSInteger key) {
|
|||||||
indent.writeln('@interface $readerName : FlutterStandardReader');
|
indent.writeln('@interface $readerName : FlutterStandardReader');
|
||||||
indent.writeln('@end');
|
indent.writeln('@end');
|
||||||
indent.writeln('@implementation $readerName');
|
indent.writeln('@implementation $readerName');
|
||||||
indent.writeln('- (nullable id)readValueOfType:(UInt8)type ');
|
indent.write('- (nullable id)readValueOfType:(UInt8)type ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.write('switch (type) ');
|
indent.write('switch (type) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
for (final EnumeratedClass customClass in codecClasses) {
|
for (final EnumeratedClass customClass in codecClasses) {
|
||||||
indent.write('case ${customClass.enumeration}: ');
|
indent.write('case ${customClass.enumeration}: ');
|
||||||
indent.writeScoped('', '', () {
|
indent.writeScoped('', '', () {
|
||||||
@ -726,33 +728,38 @@ static id GetNullableObjectAtIndex(NSArray* array, NSInteger key) {
|
|||||||
'return [${_className(options.prefix, customClass.name)} fromList:[self readValue]];');
|
'return [${_className(options.prefix, customClass.name)} fromList:[self readValue]];');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
indent.write('default:');
|
indent.writeln('default:');
|
||||||
indent.writeScoped('', '', () {
|
indent.nest(1, () {
|
||||||
indent.writeln('return [super readValueOfType:type];');
|
indent.writeln('return [super readValueOfType:type];');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
indent.writeln('@end');
|
indent.writeln('@end');
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
indent.writeln('@interface $writerName : FlutterStandardWriter');
|
indent.writeln('@interface $writerName : FlutterStandardWriter');
|
||||||
indent.writeln('@end');
|
indent.writeln('@end');
|
||||||
indent.writeln('@implementation $writerName');
|
indent.writeln('@implementation $writerName');
|
||||||
indent.writeln('- (void)writeValue:(id)value ');
|
indent.write('- (void)writeValue:(id)value ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
|
bool firstClass = true;
|
||||||
for (final EnumeratedClass customClass in codecClasses) {
|
for (final EnumeratedClass customClass in codecClasses) {
|
||||||
indent.write(
|
if (firstClass) {
|
||||||
|
indent.write('');
|
||||||
|
firstClass = false;
|
||||||
|
}
|
||||||
|
indent.add(
|
||||||
'if ([value isKindOfClass:[${_className(options.prefix, customClass.name)} class]]) ');
|
'if ([value isKindOfClass:[${_className(options.prefix, customClass.name)} class]]) ');
|
||||||
indent.scoped('{', '} else ', () {
|
indent.addScoped('{', '} else ', () {
|
||||||
indent.writeln('[self writeByte:${customClass.enumeration}];');
|
indent.writeln('[self writeByte:${customClass.enumeration}];');
|
||||||
indent.writeln('[self writeValue:[value toList]];');
|
indent.writeln('[self writeValue:[value toList]];');
|
||||||
});
|
}, addTrailingNewline: false);
|
||||||
}
|
}
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('[super writeValue:value];');
|
indent.writeln('[super writeValue:value];');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
indent.writeln('@end');
|
indent.writeln('@end');
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
indent.format('''
|
indent.format('''
|
||||||
@interface $readerWriterName : FlutterStandardReaderWriter
|
@interface $readerWriterName : FlutterStandardReaderWriter
|
||||||
@end
|
@end
|
||||||
@ -763,8 +770,7 @@ static id GetNullableObjectAtIndex(NSArray* array, NSInteger key) {
|
|||||||
- (FlutterStandardReader *)readerWithData:(NSData *)data {
|
- (FlutterStandardReader *)readerWithData:(NSData *)data {
|
||||||
\treturn [[$readerName alloc] initWithData:data];
|
\treturn [[$readerName alloc] initWithData:data];
|
||||||
}
|
}
|
||||||
@end
|
@end''');
|
||||||
''');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _writeCodecGetter(
|
void _writeCodecGetter(
|
||||||
@ -773,13 +779,13 @@ static id GetNullableObjectAtIndex(NSArray* array, NSInteger key) {
|
|||||||
|
|
||||||
indent.write(
|
indent.write(
|
||||||
'NSObject<FlutterMessageCodec> *${_getCodecGetterName(options.prefix, api.name)}() ');
|
'NSObject<FlutterMessageCodec> *${_getCodecGetterName(options.prefix, api.name)}() ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent
|
indent
|
||||||
.writeln('static FlutterStandardMessageCodec *sSharedObject = nil;');
|
.writeln('static FlutterStandardMessageCodec *sSharedObject = nil;');
|
||||||
if (getCodecClasses(api, root).isNotEmpty) {
|
if (getCodecClasses(api, root).isNotEmpty) {
|
||||||
indent.writeln('static dispatch_once_t sPred = 0;');
|
indent.writeln('static dispatch_once_t sPred = 0;');
|
||||||
indent.write('dispatch_once(&sPred, ^');
|
indent.write('dispatch_once(&sPred, ^');
|
||||||
indent.scoped('{', '});', () {
|
indent.addScoped('{', '});', () {
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'$readerWriterName *readerWriter = [[$readerWriterName alloc] init];');
|
'$readerWriterName *readerWriter = [[$readerWriterName alloc] init];');
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
@ -809,7 +815,7 @@ void _writeObjcSourceClassInitializerDeclaration(Indent indent, Class klass,
|
|||||||
final void Function(String) printer = isFirst
|
final void Function(String) printer = isFirst
|
||||||
? indent.add
|
? indent.add
|
||||||
: (String x) {
|
: (String x) {
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
indent.write(x);
|
indent.write(x);
|
||||||
};
|
};
|
||||||
isFirst = false;
|
isFirst = false;
|
||||||
@ -1057,10 +1063,10 @@ void _writeExtension(Indent indent, String apiName) {
|
|||||||
void _writeInitializer(Indent indent) {
|
void _writeInitializer(Indent indent) {
|
||||||
indent.write(
|
indent.write(
|
||||||
'- (instancetype)initWithBinaryMessenger:(NSObject<FlutterBinaryMessenger> *)binaryMessenger ');
|
'- (instancetype)initWithBinaryMessenger:(NSObject<FlutterBinaryMessenger> *)binaryMessenger ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('self = [super init];');
|
indent.writeln('self = [super init];');
|
||||||
indent.write('if (self) ');
|
indent.write('if (self) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('_binaryMessenger = binaryMessenger;');
|
indent.writeln('_binaryMessenger = binaryMessenger;');
|
||||||
});
|
});
|
||||||
indent.writeln('return self;');
|
indent.writeln('return self;');
|
||||||
@ -1091,20 +1097,21 @@ void _writeMethod(ObjcOptions languageOptions, Root root, Indent indent,
|
|||||||
argNameFunc: argNameFunc,
|
argNameFunc: argNameFunc,
|
||||||
isEnum: (TypeDeclaration t) => isEnum(root, t),
|
isEnum: (TypeDeclaration t) => isEnum(root, t),
|
||||||
));
|
));
|
||||||
indent.scoped(' {', '}', () {
|
indent.addScoped(' {', '}', () {
|
||||||
indent.writeln('FlutterBasicMessageChannel *channel =');
|
indent.writeln('FlutterBasicMessageChannel *channel =');
|
||||||
indent.inc();
|
indent.nest(1, () {
|
||||||
indent.writeln('[FlutterBasicMessageChannel');
|
indent.writeln('[FlutterBasicMessageChannel');
|
||||||
indent.inc();
|
indent.nest(1, () {
|
||||||
indent.writeln('messageChannelWithName:@"${makeChannelName(api, func)}"');
|
indent
|
||||||
|
.writeln('messageChannelWithName:@"${makeChannelName(api, func)}"');
|
||||||
indent.writeln('binaryMessenger:self.binaryMessenger');
|
indent.writeln('binaryMessenger:self.binaryMessenger');
|
||||||
indent.write(
|
indent.write(
|
||||||
'codec:${_getCodecGetterName(languageOptions.prefix, api.name)}()');
|
'codec:${_getCodecGetterName(languageOptions.prefix, api.name)}()');
|
||||||
indent.addln('];');
|
indent.addln('];');
|
||||||
indent.dec();
|
});
|
||||||
indent.dec();
|
});
|
||||||
indent.write('[channel sendMessage:$sendArgument reply:^(id reply) ');
|
indent.write('[channel sendMessage:$sendArgument reply:^(id reply) ');
|
||||||
indent.scoped('{', '}];', () {
|
indent.addScoped('{', '}];', () {
|
||||||
if (func.returnType.isVoid) {
|
if (func.returnType.isVoid) {
|
||||||
indent.writeln('completion(nil);');
|
indent.writeln('completion(nil);');
|
||||||
} else {
|
} else {
|
||||||
|
@ -61,7 +61,7 @@ class SwiftGenerator extends StructuredGenerator<SwiftOptions> {
|
|||||||
}
|
}
|
||||||
indent.writeln('// $generatedCodeWarning');
|
indent.writeln('// $generatedCodeWarning');
|
||||||
indent.writeln('// $seeAlsoWarning');
|
indent.writeln('// $seeAlsoWarning');
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -77,18 +77,18 @@ import FlutterMacOS
|
|||||||
#error("Unsupported platform.")
|
#error("Unsupported platform.")
|
||||||
#endif
|
#endif
|
||||||
''');
|
''');
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void writeEnum(
|
void writeEnum(
|
||||||
SwiftOptions generatorOptions, Root root, Indent indent, Enum anEnum) {
|
SwiftOptions generatorOptions, Root root, Indent indent, Enum anEnum) {
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
addDocumentationComments(
|
addDocumentationComments(
|
||||||
indent, anEnum.documentationComments, _docCommentSpec);
|
indent, anEnum.documentationComments, _docCommentSpec);
|
||||||
|
|
||||||
indent.write('enum ${anEnum.name}: Int ');
|
indent.write('enum ${anEnum.name}: Int ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
enumerate(anEnum.members, (int index, final EnumMember member) {
|
enumerate(anEnum.members, (int index, final EnumMember member) {
|
||||||
addDocumentationComments(
|
addDocumentationComments(
|
||||||
indent, member.documentationComments, _docCommentSpec);
|
indent, member.documentationComments, _docCommentSpec);
|
||||||
@ -108,18 +108,18 @@ import FlutterMacOS
|
|||||||
const List<String> generatedComments = <String>[
|
const List<String> generatedComments = <String>[
|
||||||
' Generated class from Pigeon that represents data sent in messages.'
|
' Generated class from Pigeon that represents data sent in messages.'
|
||||||
];
|
];
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
addDocumentationComments(
|
addDocumentationComments(
|
||||||
indent, klass.documentationComments, _docCommentSpec,
|
indent, klass.documentationComments, _docCommentSpec,
|
||||||
generatorComments: generatedComments);
|
generatorComments: generatedComments);
|
||||||
|
|
||||||
indent.write('struct ${klass.name} ');
|
indent.write('struct ${klass.name} ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
getFieldsInSerializationOrder(klass).forEach((NamedType field) {
|
getFieldsInSerializationOrder(klass).forEach((NamedType field) {
|
||||||
_writeClassField(indent, field);
|
_writeClassField(indent, field);
|
||||||
});
|
});
|
||||||
|
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
writeClassDecode(generatorOptions, root, indent, klass, customClassNames,
|
writeClassDecode(generatorOptions, root, indent, klass, customClassNames,
|
||||||
customEnumNames);
|
customEnumNames);
|
||||||
writeClassEncode(generatorOptions, root, indent, klass, customClassNames,
|
writeClassEncode(generatorOptions, root, indent, klass, customClassNames,
|
||||||
@ -137,9 +137,9 @@ import FlutterMacOS
|
|||||||
Set<String> customEnumNames,
|
Set<String> customEnumNames,
|
||||||
) {
|
) {
|
||||||
indent.write('func toList() -> [Any?] ');
|
indent.write('func toList() -> [Any?] ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.write('return ');
|
indent.write('return ');
|
||||||
indent.scoped('[', ']', () {
|
indent.addScoped('[', ']', () {
|
||||||
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
|
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
|
||||||
final HostDatatype hostDatatype = _getHostDatatype(root, field);
|
final HostDatatype hostDatatype = _getHostDatatype(root, field);
|
||||||
String toWriteValue = '';
|
String toWriteValue = '';
|
||||||
@ -173,7 +173,7 @@ import FlutterMacOS
|
|||||||
final String className = klass.name;
|
final String className = klass.name;
|
||||||
indent.write('static func fromList(_ list: [Any?]) -> $className? ');
|
indent.write('static func fromList(_ list: [Any?]) -> $className? ');
|
||||||
|
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
enumerate(getFieldsInSerializationOrder(klass),
|
enumerate(getFieldsInSerializationOrder(klass),
|
||||||
(int index, final NamedType field) {
|
(int index, final NamedType field) {
|
||||||
final HostDatatype hostDatatype = _getHostDatatype(root, field);
|
final HostDatatype hostDatatype = _getHostDatatype(root, field);
|
||||||
@ -186,7 +186,7 @@ import FlutterMacOS
|
|||||||
customClassNames.contains(field.type.baseName)) {
|
customClassNames.contains(field.type.baseName)) {
|
||||||
indent.writeln('var ${field.name}: $fieldType? = nil');
|
indent.writeln('var ${field.name}: $fieldType? = nil');
|
||||||
indent.write('if let ${field.name}List = $listValue as? [Any?] ');
|
indent.write('if let ${field.name}List = $listValue as? [Any?] ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'${field.name} = $fieldType.fromList(${field.name}List)');
|
'${field.name} = $fieldType.fromList(${field.name}List)');
|
||||||
});
|
});
|
||||||
@ -194,7 +194,7 @@ import FlutterMacOS
|
|||||||
customEnumNames.contains(field.type.baseName)) {
|
customEnumNames.contains(field.type.baseName)) {
|
||||||
indent.writeln('var ${field.name}: $fieldType? = nil');
|
indent.writeln('var ${field.name}: $fieldType? = nil');
|
||||||
indent.write('if let ${field.name}RawValue = $listValue as? Int ');
|
indent.write('if let ${field.name}RawValue = $listValue as? Int ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'${field.name} = $fieldType(rawValue: ${field.name}RawValue)');
|
'${field.name} = $fieldType(rawValue: ${field.name}RawValue)');
|
||||||
});
|
});
|
||||||
@ -216,9 +216,9 @@ import FlutterMacOS
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
indent.write('return ');
|
indent.write('return ');
|
||||||
indent.scoped('$className(', ')', () {
|
indent.addScoped('$className(', ')', () {
|
||||||
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
|
for (final NamedType field in getFieldsInSerializationOrder(klass)) {
|
||||||
final String comma =
|
final String comma =
|
||||||
getFieldsInSerializationOrder(klass).last == field ? '' : ',';
|
getFieldsInSerializationOrder(klass).last == field ? '' : ',';
|
||||||
@ -247,7 +247,7 @@ import FlutterMacOS
|
|||||||
if (root.apis.any((Api api) =>
|
if (root.apis.any((Api api) =>
|
||||||
api.location == ApiLocation.host &&
|
api.location == ApiLocation.host &&
|
||||||
api.methods.any((Method it) => it.isAsynchronous))) {
|
api.methods.any((Method it) => it.isAsynchronous))) {
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
super.writeApis(generatorOptions, root, indent);
|
super.writeApis(generatorOptions, root, indent);
|
||||||
}
|
}
|
||||||
@ -278,10 +278,10 @@ import FlutterMacOS
|
|||||||
generatorComments: generatedComments);
|
generatorComments: generatedComments);
|
||||||
|
|
||||||
indent.write('class ${api.name} ');
|
indent.write('class ${api.name} ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('private let binaryMessenger: FlutterBinaryMessenger');
|
indent.writeln('private let binaryMessenger: FlutterBinaryMessenger');
|
||||||
indent.write('init(binaryMessenger: FlutterBinaryMessenger)');
|
indent.write('init(binaryMessenger: FlutterBinaryMessenger)');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('self.binaryMessenger = binaryMessenger');
|
indent.writeln('self.binaryMessenger = binaryMessenger');
|
||||||
});
|
});
|
||||||
final String codecName = _getCodecName(api);
|
final String codecName = _getCodecName(api);
|
||||||
@ -289,7 +289,7 @@ import FlutterMacOS
|
|||||||
if (getCodecClasses(api, root).isNotEmpty) {
|
if (getCodecClasses(api, root).isNotEmpty) {
|
||||||
codecArgumentString = ', codec: codec';
|
codecArgumentString = ', codec: codec';
|
||||||
indent.write('var codec: FlutterStandardMessageCodec ');
|
indent.write('var codec: FlutterStandardMessageCodec ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('return $codecName.shared');
|
indent.writeln('return $codecName.shared');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -328,17 +328,17 @@ import FlutterMacOS
|
|||||||
'func ${func.name}($argsSignature, completion: @escaping ($returnType) -> Void) ');
|
'func ${func.name}($argsSignature, completion: @escaping ($returnType) -> Void) ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
const String channel = 'channel';
|
const String channel = 'channel';
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'let $channel = FlutterBasicMessageChannel(name: "$channelName", binaryMessenger: binaryMessenger$codecArgumentString)');
|
'let $channel = FlutterBasicMessageChannel(name: "$channelName", binaryMessenger: binaryMessenger$codecArgumentString)');
|
||||||
indent.write('$channel.sendMessage($sendArgument) ');
|
indent.write('$channel.sendMessage($sendArgument) ');
|
||||||
if (func.returnType.isVoid) {
|
if (func.returnType.isVoid) {
|
||||||
indent.scoped('{ _ in', '}', () {
|
indent.addScoped('{ _ in', '}', () {
|
||||||
indent.writeln('completion()');
|
indent.writeln('completion()');
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
indent.scoped('{ response in', '}', () {
|
indent.addScoped('{ response in', '}', () {
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'let result = ${_castForceUnwrap("response", func.returnType, root)}');
|
'let result = ${_castForceUnwrap("response", func.returnType, root)}');
|
||||||
indent.writeln('completion(result)');
|
indent.writeln('completion(result)');
|
||||||
@ -377,7 +377,7 @@ import FlutterMacOS
|
|||||||
generatorComments: generatedComments);
|
generatorComments: generatedComments);
|
||||||
|
|
||||||
indent.write('protocol $apiName ');
|
indent.write('protocol $apiName ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
for (final Method method in api.methods) {
|
for (final Method method in api.methods) {
|
||||||
final List<String> argSignature = <String>[];
|
final List<String> argSignature = <String>[];
|
||||||
if (method.arguments.isNotEmpty) {
|
if (method.arguments.isNotEmpty) {
|
||||||
@ -409,11 +409,11 @@ import FlutterMacOS
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'$_docCommentPrefix Generated setup class from Pigeon to handle messages through the `binaryMessenger`.');
|
'$_docCommentPrefix Generated setup class from Pigeon to handle messages through the `binaryMessenger`.');
|
||||||
indent.write('class ${apiName}Setup ');
|
indent.write('class ${apiName}Setup ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
final String codecName = _getCodecName(api);
|
final String codecName = _getCodecName(api);
|
||||||
indent.writeln('$_docCommentPrefix The codec used by $apiName.');
|
indent.writeln('$_docCommentPrefix The codec used by $apiName.');
|
||||||
String codecArgumentString = '';
|
String codecArgumentString = '';
|
||||||
@ -426,7 +426,7 @@ import FlutterMacOS
|
|||||||
'$_docCommentPrefix Sets up an instance of `$apiName` to handle messages through the `binaryMessenger`.');
|
'$_docCommentPrefix Sets up an instance of `$apiName` to handle messages through the `binaryMessenger`.');
|
||||||
indent.write(
|
indent.write(
|
||||||
'static func setUp(binaryMessenger: FlutterBinaryMessenger, api: $apiName?) ');
|
'static func setUp(binaryMessenger: FlutterBinaryMessenger, api: $apiName?) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
for (final Method method in api.methods) {
|
for (final Method method in api.methods) {
|
||||||
final String channelName = makeChannelName(api, method);
|
final String channelName = makeChannelName(api, method);
|
||||||
final String varChannelName = '${method.name}Channel';
|
final String varChannelName = '${method.name}Channel';
|
||||||
@ -436,11 +436,11 @@ import FlutterMacOS
|
|||||||
indent.writeln(
|
indent.writeln(
|
||||||
'let $varChannelName = FlutterBasicMessageChannel(name: "$channelName", binaryMessenger: binaryMessenger$codecArgumentString)');
|
'let $varChannelName = FlutterBasicMessageChannel(name: "$channelName", binaryMessenger: binaryMessenger$codecArgumentString)');
|
||||||
indent.write('if let api = api ');
|
indent.write('if let api = api ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.write('$varChannelName.setMessageHandler ');
|
indent.write('$varChannelName.setMessageHandler ');
|
||||||
final String messageVarName =
|
final String messageVarName =
|
||||||
method.arguments.isNotEmpty ? 'message' : '_';
|
method.arguments.isNotEmpty ? 'message' : '_';
|
||||||
indent.scoped('{ $messageVarName, reply in', '}', () {
|
indent.addScoped('{ $messageVarName, reply in', '}', () {
|
||||||
final List<String> methodArgument = <String>[];
|
final List<String> methodArgument = <String>[];
|
||||||
if (method.arguments.isNotEmpty) {
|
if (method.arguments.isNotEmpty) {
|
||||||
indent.writeln('let args = message as! [Any?]');
|
indent.writeln('let args = message as! [Any?]');
|
||||||
@ -457,11 +457,11 @@ import FlutterMacOS
|
|||||||
if (method.isAsynchronous) {
|
if (method.isAsynchronous) {
|
||||||
indent.write('$call ');
|
indent.write('$call ');
|
||||||
if (method.returnType.isVoid) {
|
if (method.returnType.isVoid) {
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('reply(wrapResult(nil))');
|
indent.writeln('reply(wrapResult(nil))');
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
indent.scoped('{ result in', '}', () {
|
indent.addScoped('{ result in', '}', () {
|
||||||
indent.writeln('reply(wrapResult(result))');
|
indent.writeln('reply(wrapResult(result))');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -476,7 +476,7 @@ import FlutterMacOS
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, addTrailingNewline: false);
|
}, addTrailingNewline: false);
|
||||||
indent.scoped(' else {', '}', () {
|
indent.addScoped(' else {', '}', () {
|
||||||
indent.writeln('$varChannelName.setMessageHandler(nil)');
|
indent.writeln('$varChannelName.setMessageHandler(nil)');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -498,22 +498,22 @@ import FlutterMacOS
|
|||||||
|
|
||||||
// Generate Reader
|
// Generate Reader
|
||||||
indent.write('private class $readerName: FlutterStandardReader ');
|
indent.write('private class $readerName: FlutterStandardReader ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
if (getCodecClasses(api, root).isNotEmpty) {
|
if (getCodecClasses(api, root).isNotEmpty) {
|
||||||
indent.write('override func readValue(ofType type: UInt8) -> Any? ');
|
indent.write('override func readValue(ofType type: UInt8) -> Any? ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.write('switch type ');
|
indent.write('switch type ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
for (final EnumeratedClass customClass
|
for (final EnumeratedClass customClass
|
||||||
in getCodecClasses(api, root)) {
|
in getCodecClasses(api, root)) {
|
||||||
indent.write('case ${customClass.enumeration}:');
|
indent.writeln('case ${customClass.enumeration}:');
|
||||||
indent.scoped('', '', () {
|
indent.nest(1, () {
|
||||||
indent.write(
|
indent.writeln(
|
||||||
'return ${customClass.name}.fromList(self.readValue() as! [Any])');
|
'return ${customClass.name}.fromList(self.readValue() as! [Any])');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
indent.write('default:');
|
indent.writeln('default:');
|
||||||
indent.scoped('', '', () {
|
indent.nest(1, () {
|
||||||
indent.writeln('return super.readValue(ofType: type)');
|
indent.writeln('return super.readValue(ofType: type)');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -522,69 +522,70 @@ import FlutterMacOS
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Generate Writer
|
// Generate Writer
|
||||||
|
indent.newln();
|
||||||
indent.write('private class $writerName: FlutterStandardWriter ');
|
indent.write('private class $writerName: FlutterStandardWriter ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
if (getCodecClasses(api, root).isNotEmpty) {
|
if (getCodecClasses(api, root).isNotEmpty) {
|
||||||
indent.write('override func writeValue(_ value: Any) ');
|
indent.write('override func writeValue(_ value: Any) ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.write('');
|
indent.write('');
|
||||||
for (final EnumeratedClass customClass
|
for (final EnumeratedClass customClass
|
||||||
in getCodecClasses(api, root)) {
|
in getCodecClasses(api, root)) {
|
||||||
indent.add('if let value = value as? ${customClass.name} ');
|
indent.add('if let value = value as? ${customClass.name} ');
|
||||||
indent.scoped('{', '} else ', () {
|
indent.addScoped('{', '} else ', () {
|
||||||
indent.writeln('super.writeByte(${customClass.enumeration})');
|
indent.writeln('super.writeByte(${customClass.enumeration})');
|
||||||
indent.writeln('super.writeValue(value.toList())');
|
indent.writeln('super.writeValue(value.toList())');
|
||||||
}, addTrailingNewline: false);
|
}, addTrailingNewline: false);
|
||||||
}
|
}
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('super.writeValue(value)');
|
indent.writeln('super.writeValue(value)');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
|
|
||||||
// Generate ReaderWriter
|
// Generate ReaderWriter
|
||||||
indent
|
indent
|
||||||
.write('private class $readerWriterName: FlutterStandardReaderWriter ');
|
.write('private class $readerWriterName: FlutterStandardReaderWriter ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.write(
|
indent.write(
|
||||||
'override func reader(with data: Data) -> FlutterStandardReader ');
|
'override func reader(with data: Data) -> FlutterStandardReader ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('return $readerName(data: data)');
|
indent.writeln('return $readerName(data: data)');
|
||||||
});
|
});
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
indent.write(
|
indent.write(
|
||||||
'override func writer(with data: NSMutableData) -> FlutterStandardWriter ');
|
'override func writer(with data: NSMutableData) -> FlutterStandardWriter ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('return $writerName(data: data)');
|
indent.writeln('return $writerName(data: data)');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
indent.writeln('');
|
indent.newln();
|
||||||
|
|
||||||
// Generate Codec
|
// Generate Codec
|
||||||
indent.write('class $codecName: FlutterStandardMessageCodec ');
|
indent.write('class $codecName: FlutterStandardMessageCodec ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln(
|
indent.writeln(
|
||||||
'static let shared = $codecName(readerWriter: $readerWriterName())');
|
'static let shared = $codecName(readerWriter: $readerWriterName())');
|
||||||
});
|
});
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _writeWrapResult(Indent indent) {
|
void _writeWrapResult(Indent indent) {
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
indent.write('private func wrapResult(_ result: Any?) -> [Any?] ');
|
indent.write('private func wrapResult(_ result: Any?) -> [Any?] ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.writeln('return [result]');
|
indent.writeln('return [result]');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _writeWrapError(Indent indent) {
|
void _writeWrapError(Indent indent) {
|
||||||
indent.addln('');
|
indent.newln();
|
||||||
indent.write('private func wrapError(_ error: FlutterError) -> [Any?] ');
|
indent.write('private func wrapError(_ error: FlutterError) -> [Any?] ');
|
||||||
indent.scoped('{', '}', () {
|
indent.addScoped('{', '}', () {
|
||||||
indent.write('return ');
|
indent.write('return ');
|
||||||
indent.scoped('[', ']', () {
|
indent.addScoped('[', ']', () {
|
||||||
indent.writeln('error.code,');
|
indent.writeln('error.code,');
|
||||||
indent.writeln('error.message,');
|
indent.writeln('error.message,');
|
||||||
indent.writeln('error.details');
|
indent.writeln('error.details');
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
//
|
//
|
||||||
// Autogenerated from Pigeon (v7.0.0), do not edit directly.
|
// Autogenerated from Pigeon (v7.0.1), do not edit directly.
|
||||||
// See also: https://pub.dev/packages/pigeon
|
// See also: https://pub.dev/packages/pigeon
|
||||||
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import
|
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
//
|
//
|
||||||
// Autogenerated from Pigeon (v7.0.0), do not edit directly.
|
// Autogenerated from Pigeon (v7.0.1), do not edit directly.
|
||||||
// See also: https://pub.dev/packages/pigeon
|
// See also: https://pub.dev/packages/pigeon
|
||||||
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import
|
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import
|
||||||
// ignore_for_file: avoid_relative_lib_imports
|
// ignore_for_file: avoid_relative_lib_imports
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
//
|
//
|
||||||
// Autogenerated from Pigeon (v7.0.0), do not edit directly.
|
// Autogenerated from Pigeon (v7.0.1), do not edit directly.
|
||||||
// See also: https://pub.dev/packages/pigeon
|
// See also: https://pub.dev/packages/pigeon
|
||||||
|
|
||||||
package com.example.alternate_language_test_plugin;
|
package com.example.alternate_language_test_plugin;
|
||||||
@ -196,6 +196,7 @@ public class CoreTests {
|
|||||||
private AllTypes() {}
|
private AllTypes() {}
|
||||||
|
|
||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
|
|
||||||
private @Nullable Boolean aBool;
|
private @Nullable Boolean aBool;
|
||||||
|
|
||||||
public @NonNull Builder setABool(@NonNull Boolean setterArg) {
|
public @NonNull Builder setABool(@NonNull Boolean setterArg) {
|
||||||
@ -479,6 +480,7 @@ public class CoreTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
|
|
||||||
private @Nullable Boolean aNullableBool;
|
private @Nullable Boolean aNullableBool;
|
||||||
|
|
||||||
public @NonNull Builder setANullableBool(@Nullable Boolean setterArg) {
|
public @NonNull Builder setANullableBool(@Nullable Boolean setterArg) {
|
||||||
@ -675,6 +677,7 @@ public class CoreTests {
|
|||||||
private AllNullableTypesWrapper() {}
|
private AllNullableTypesWrapper() {}
|
||||||
|
|
||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
|
|
||||||
private @Nullable AllNullableTypes values;
|
private @Nullable AllNullableTypes values;
|
||||||
|
|
||||||
public @NonNull Builder setValues(@NonNull AllNullableTypes setterArg) {
|
public @NonNull Builder setValues(@NonNull AllNullableTypes setterArg) {
|
||||||
@ -2177,6 +2180,7 @@ public class CoreTests {
|
|||||||
public FlutterIntegrationCoreApi(BinaryMessenger argBinaryMessenger) {
|
public FlutterIntegrationCoreApi(BinaryMessenger argBinaryMessenger) {
|
||||||
this.binaryMessenger = argBinaryMessenger;
|
this.binaryMessenger = argBinaryMessenger;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Public interface for sending reply. */
|
/** Public interface for sending reply. */
|
||||||
public interface Reply<T> {
|
public interface Reply<T> {
|
||||||
void reply(T reply);
|
void reply(T reply);
|
||||||
@ -2459,6 +2463,7 @@ public class CoreTests {
|
|||||||
* <p>Generated interface from Pigeon that represents a handler of messages from Flutter.
|
* <p>Generated interface from Pigeon that represents a handler of messages from Flutter.
|
||||||
*/
|
*/
|
||||||
public interface HostTrivialApi {
|
public interface HostTrivialApi {
|
||||||
|
|
||||||
void noop();
|
void noop();
|
||||||
|
|
||||||
/** The codec used by HostTrivialApi. */
|
/** The codec used by HostTrivialApi. */
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
//
|
//
|
||||||
// Autogenerated from Pigeon (v7.0.0), do not edit directly.
|
// Autogenerated from Pigeon (v7.0.1), do not edit directly.
|
||||||
// See also: https://pub.dev/packages/pigeon
|
// See also: https://pub.dev/packages/pigeon
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
//
|
//
|
||||||
// Autogenerated from Pigeon (v7.0.0), do not edit directly.
|
// Autogenerated from Pigeon (v7.0.1), do not edit directly.
|
||||||
// See also: https://pub.dev/packages/pigeon
|
// See also: https://pub.dev/packages/pigeon
|
||||||
|
|
||||||
#import "CoreTests.gen.h"
|
#import "CoreTests.gen.h"
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
//
|
//
|
||||||
// Autogenerated from Pigeon (v7.0.0), do not edit directly.
|
// Autogenerated from Pigeon (v7.0.1), do not edit directly.
|
||||||
// See also: https://pub.dev/packages/pigeon
|
// See also: https://pub.dev/packages/pigeon
|
||||||
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import
|
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
//
|
//
|
||||||
// Autogenerated from Pigeon (v7.0.0), do not edit directly.
|
// Autogenerated from Pigeon (v7.0.1), do not edit directly.
|
||||||
// See also: https://pub.dev/packages/pigeon
|
// See also: https://pub.dev/packages/pigeon
|
||||||
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import
|
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
//
|
//
|
||||||
// Autogenerated from Pigeon (v7.0.0), do not edit directly.
|
// Autogenerated from Pigeon (v7.0.1), do not edit directly.
|
||||||
// See also: https://pub.dev/packages/pigeon
|
// See also: https://pub.dev/packages/pigeon
|
||||||
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import
|
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
//
|
//
|
||||||
// Autogenerated from Pigeon (v7.0.0), do not edit directly.
|
// Autogenerated from Pigeon (v7.0.1), do not edit directly.
|
||||||
// See also: https://pub.dev/packages/pigeon
|
// See also: https://pub.dev/packages/pigeon
|
||||||
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import
|
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
//
|
//
|
||||||
// Autogenerated from Pigeon (v7.0.0), do not edit directly.
|
// Autogenerated from Pigeon (v7.0.1), do not edit directly.
|
||||||
// See also: https://pub.dev/packages/pigeon
|
// See also: https://pub.dev/packages/pigeon
|
||||||
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import
|
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
//
|
//
|
||||||
// Autogenerated from Pigeon (v7.0.0), do not edit directly.
|
// Autogenerated from Pigeon (v7.0.1), do not edit directly.
|
||||||
// See also: https://pub.dev/packages/pigeon
|
// See also: https://pub.dev/packages/pigeon
|
||||||
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import
|
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
//
|
//
|
||||||
// Autogenerated from Pigeon (v7.0.0), do not edit directly.
|
// Autogenerated from Pigeon (v7.0.1), do not edit directly.
|
||||||
// See also: https://pub.dev/packages/pigeon
|
// See also: https://pub.dev/packages/pigeon
|
||||||
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import
|
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
//
|
//
|
||||||
// Autogenerated from Pigeon (v7.0.0), do not edit directly.
|
// Autogenerated from Pigeon (v7.0.1), do not edit directly.
|
||||||
// See also: https://pub.dev/packages/pigeon
|
// See also: https://pub.dev/packages/pigeon
|
||||||
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import
|
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
//
|
//
|
||||||
// Autogenerated from Pigeon (v7.0.0), do not edit directly.
|
// Autogenerated from Pigeon (v7.0.1), do not edit directly.
|
||||||
// See also: https://pub.dev/packages/pigeon
|
// See also: https://pub.dev/packages/pigeon
|
||||||
|
|
||||||
package com.example.test_plugin
|
package com.example.test_plugin
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
//
|
//
|
||||||
// Autogenerated from Pigeon (v7.0.0), do not edit directly.
|
// Autogenerated from Pigeon (v7.0.1), do not edit directly.
|
||||||
// See also: https://pub.dev/packages/pigeon
|
// See also: https://pub.dev/packages/pigeon
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
@ -194,10 +194,10 @@ private class HostIntegrationCoreApiCodecReader: FlutterStandardReader {
|
|||||||
return AllTypes.fromList(self.readValue() as! [Any])
|
return AllTypes.fromList(self.readValue() as! [Any])
|
||||||
default:
|
default:
|
||||||
return super.readValue(ofType: type)
|
return super.readValue(ofType: type)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private class HostIntegrationCoreApiCodecWriter: FlutterStandardWriter {
|
private class HostIntegrationCoreApiCodecWriter: FlutterStandardWriter {
|
||||||
override func writeValue(_ value: Any) {
|
override func writeValue(_ value: Any) {
|
||||||
if let value = value as? AllNullableTypes {
|
if let value = value as? AllNullableTypes {
|
||||||
@ -776,10 +776,10 @@ private class FlutterIntegrationCoreApiCodecReader: FlutterStandardReader {
|
|||||||
return AllTypes.fromList(self.readValue() as! [Any])
|
return AllTypes.fromList(self.readValue() as! [Any])
|
||||||
default:
|
default:
|
||||||
return super.readValue(ofType: type)
|
return super.readValue(ofType: type)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private class FlutterIntegrationCoreApiCodecWriter: FlutterStandardWriter {
|
private class FlutterIntegrationCoreApiCodecWriter: FlutterStandardWriter {
|
||||||
override func writeValue(_ value: Any) {
|
override func writeValue(_ value: Any) {
|
||||||
if let value = value as? AllNullableTypes {
|
if let value = value as? AllNullableTypes {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
//
|
//
|
||||||
// Autogenerated from Pigeon (v7.0.0), do not edit directly.
|
// Autogenerated from Pigeon (v7.0.1), do not edit directly.
|
||||||
// See also: https://pub.dev/packages/pigeon
|
// See also: https://pub.dev/packages/pigeon
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
@ -194,10 +194,10 @@ private class HostIntegrationCoreApiCodecReader: FlutterStandardReader {
|
|||||||
return AllTypes.fromList(self.readValue() as! [Any])
|
return AllTypes.fromList(self.readValue() as! [Any])
|
||||||
default:
|
default:
|
||||||
return super.readValue(ofType: type)
|
return super.readValue(ofType: type)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private class HostIntegrationCoreApiCodecWriter: FlutterStandardWriter {
|
private class HostIntegrationCoreApiCodecWriter: FlutterStandardWriter {
|
||||||
override func writeValue(_ value: Any) {
|
override func writeValue(_ value: Any) {
|
||||||
if let value = value as? AllNullableTypes {
|
if let value = value as? AllNullableTypes {
|
||||||
@ -776,10 +776,10 @@ private class FlutterIntegrationCoreApiCodecReader: FlutterStandardReader {
|
|||||||
return AllTypes.fromList(self.readValue() as! [Any])
|
return AllTypes.fromList(self.readValue() as! [Any])
|
||||||
default:
|
default:
|
||||||
return super.readValue(ofType: type)
|
return super.readValue(ofType: type)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private class FlutterIntegrationCoreApiCodecWriter: FlutterStandardWriter {
|
private class FlutterIntegrationCoreApiCodecWriter: FlutterStandardWriter {
|
||||||
override func writeValue(_ value: Any) {
|
override func writeValue(_ value: Any) {
|
||||||
if let value = value as? AllNullableTypes {
|
if let value = value as? AllNullableTypes {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
//
|
//
|
||||||
// Autogenerated from Pigeon (v7.0.0), do not edit directly.
|
// Autogenerated from Pigeon (v7.0.1), do not edit directly.
|
||||||
// See also: https://pub.dev/packages/pigeon
|
// See also: https://pub.dev/packages/pigeon
|
||||||
|
|
||||||
#undef _HAS_EXCEPTIONS
|
#undef _HAS_EXCEPTIONS
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
//
|
//
|
||||||
// Autogenerated from Pigeon (v7.0.0), do not edit directly.
|
// Autogenerated from Pigeon (v7.0.1), do not edit directly.
|
||||||
// See also: https://pub.dev/packages/pigeon
|
// See also: https://pub.dev/packages/pigeon
|
||||||
|
|
||||||
#ifndef PIGEON_CORE_TESTS_GEN_H_
|
#ifndef PIGEON_CORE_TESTS_GEN_H_
|
||||||
|
@ -2,7 +2,7 @@ name: pigeon
|
|||||||
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
|
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
|
||||||
repository: https://github.com/flutter/packages/tree/main/packages/pigeon
|
repository: https://github.com/flutter/packages/tree/main/packages/pigeon
|
||||||
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Apigeon
|
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Apigeon
|
||||||
version: 7.0.0 # This must match the version in lib/generator_tools.dart
|
version: 7.0.1 # This must match the version in lib/generator_tools.dart
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.12.0 <3.0.0"
|
sdk: ">=2.12.0 <3.0.0"
|
||||||
|
@ -36,8 +36,8 @@ void main() {
|
|||||||
expect(code, contains('private @Nullable Long field1;'));
|
expect(code, contains('private @Nullable Long field1;'));
|
||||||
expect(
|
expect(
|
||||||
code,
|
code,
|
||||||
contains(
|
contains(RegExp(
|
||||||
'@NonNull private static ArrayList<Object> wrapError(@NonNull Throwable exception)'));
|
r'@NonNull\s*private static ArrayList<Object> wrapError\(@NonNull Throwable exception\)')));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('gen one enum', () {
|
test('gen one enum', () {
|
||||||
@ -386,7 +386,7 @@ void main() {
|
|||||||
generator.generate(javaOptions, root, sink);
|
generator.generate(javaOptions, root, sink);
|
||||||
final String code = sink.toString();
|
final String code = sink.toString();
|
||||||
expect(code, contains('doSomething(Reply<Output>'));
|
expect(code, contains('doSomething(Reply<Output>'));
|
||||||
expect(code, contains('channel.send(null'));
|
expect(code, contains(RegExp(r'channel.send\(\s*null')));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('gen list', () {
|
test('gen list', () {
|
||||||
@ -888,8 +888,8 @@ void main() {
|
|||||||
final String code = sink.toString();
|
final String code = sink.toString();
|
||||||
expect(code, contains('class Messages'));
|
expect(code, contains('class Messages'));
|
||||||
expect(code, contains('Long add(@NonNull Long x, @NonNull Long y)'));
|
expect(code, contains('Long add(@NonNull Long x, @NonNull Long y)'));
|
||||||
expect(
|
expect(code,
|
||||||
code, contains('ArrayList<Object> args = (ArrayList<Object>)message;'));
|
contains('ArrayList<Object> args = (ArrayList<Object>) message;'));
|
||||||
expect(code, contains('Number xArg = (Number) args.get(0)'));
|
expect(code, contains('Number xArg = (Number) args.get(0)'));
|
||||||
expect(code, contains('Number yArg = (Number) args.get(1)'));
|
expect(code, contains('Number yArg = (Number) args.get(1)'));
|
||||||
expect(
|
expect(
|
||||||
@ -954,8 +954,8 @@ void main() {
|
|||||||
'public void add(@NonNull Long xArg, @NonNull Long yArg, Reply<Long> callback)'));
|
'public void add(@NonNull Long xArg, @NonNull Long yArg, Reply<Long> callback)'));
|
||||||
expect(
|
expect(
|
||||||
code,
|
code,
|
||||||
contains(
|
contains(RegExp(
|
||||||
'channel.send(new ArrayList<Object>(Arrays.asList(xArg, yArg)), channelReply ->'));
|
r'channel.send\(\s*new ArrayList<Object>\(Arrays.asList\(xArg, yArg\)\),\s*channelReply ->')));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('flutter single args', () {
|
test('flutter single args', () {
|
||||||
@ -980,8 +980,8 @@ void main() {
|
|||||||
final String code = sink.toString();
|
final String code = sink.toString();
|
||||||
expect(
|
expect(
|
||||||
code,
|
code,
|
||||||
contains(
|
contains(RegExp(
|
||||||
'channel.send(new ArrayList<Object>(Collections.singletonList(xArg)), channelReply ->'));
|
r'channel.send\(\s*new ArrayList<Object>\(Collections.singletonList\(xArg\)\),\s*channelReply ->')));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('return nullable host', () {
|
test('return nullable host', () {
|
||||||
@ -1005,7 +1005,7 @@ void main() {
|
|||||||
const JavaGenerator generator = JavaGenerator();
|
const JavaGenerator generator = JavaGenerator();
|
||||||
generator.generate(javaOptions, root, sink);
|
generator.generate(javaOptions, root, sink);
|
||||||
final String code = sink.toString();
|
final String code = sink.toString();
|
||||||
expect(code, contains('@Nullable Long doit();'));
|
expect(code, contains(RegExp(r'@Nullable\s*Long doit\(\);')));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('return nullable host async', () {
|
test('return nullable host async', () {
|
||||||
@ -1125,8 +1125,8 @@ void main() {
|
|||||||
'BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue();'));
|
'BinaryMessenger.TaskQueue taskQueue = binaryMessenger.makeBackgroundTaskQueue();'));
|
||||||
expect(
|
expect(
|
||||||
code,
|
code,
|
||||||
contains(
|
contains(RegExp(
|
||||||
'new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.Api.doit", getCodec(), taskQueue)'));
|
r'new BasicMessageChannel<>\(\s*binaryMessenger, "dev.flutter.pigeon.Api.doit", getCodec\(\), taskQueue\)')));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('generated annotation', () {
|
test('generated annotation', () {
|
||||||
|
Reference in New Issue
Block a user