Skip to content

Commit

Permalink
[Pigeon] Fixed primitive datatypes for java. (flutter#119)
Browse files Browse the repository at this point in the history
* [Pigeon] Fixed primitive datatypes for java.
  • Loading branch information
gaaclarke authored Mar 19, 2020
1 parent 2463514 commit bbdaf80
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
4 changes: 4 additions & 0 deletions packages/pigeon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.0-experimental.4

* Fixed primitive types for Android Java.

## 0.1.0-experimental.3

* Added support for for Android Java.
Expand Down
12 changes: 6 additions & 6 deletions packages/pigeon/lib/generator_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ class HostDatatype {
/// `builtinResolver` will return the host datatype for the Dart datatype for
/// builtin types. `customResolver` can modify the datatype of custom types.
HostDatatype getHostDatatype(
Field field,
List<Class> classes,
String Function(String) builtinResolver,
String Function(String) customResolver) {
Field field, List<Class> classes, String Function(String) builtinResolver,
{String Function(String) customResolver}) {
final String datatype = builtinResolver(field.dataType);
if (datatype == null) {
if (classes.map((Class x) => x.name).contains(field.dataType)) {
return HostDatatype(
datatype: customResolver(field.dataType), isBuiltin: false);
final String customName = customResolver != null
? customResolver(field.dataType)
: field.dataType;
return HostDatatype(datatype: customName, isBuiltin: false);
} else {
return null;
}
Expand Down
8 changes: 5 additions & 3 deletions packages/pigeon/lib/java_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ void generateJava(JavaOptions options, Root root, StringSink sink) {
indent.write('public static class ${klass.name} ');
indent.scoped('{', '}', () {
for (Field field in klass.fields) {
final HostDatatype hostDatatype = getHostDatatype(
field, root.classes, _javaTypeForDartType, (String x) => x);
final HostDatatype hostDatatype =
getHostDatatype(field, root.classes, _javaTypeForDartType);
indent.writeln('private ${hostDatatype.datatype} ${field.name};');
indent.writeln(
'public ${hostDatatype.datatype} ${_makeGetter(field)}() { return ${field.name}; }');
Expand All @@ -197,8 +197,10 @@ void generateJava(JavaOptions options, Root root, StringSink sink) {
indent.scoped('{', '}', () {
indent.writeln('${klass.name} fromMapResult = new ${klass.name}();');
for (Field field in klass.fields) {
final HostDatatype hostDatatype =
getHostDatatype(field, root.classes, _javaTypeForDartType);
indent.writeln(
'fromMapResult.${field.name} = (${field.dataType})map.get("${field.name}");');
'fromMapResult.${field.name} = (${hostDatatype.datatype})map.get("${field.name}");');
}
indent.writeln('return fromMapResult;');
});
Expand Down
6 changes: 2 additions & 4 deletions packages/pigeon/lib/objc_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,8 @@ void generateObjcHeader(ObjcOptions options, Root root, StringSink sink) {
'@interface ${_className(options.prefix, klass.name)} : NSObject ');
for (Field field in klass.fields) {
final HostDatatype hostDatatype = getHostDatatype(
field,
root.classes,
_objcTypeForDartType,
(String x) => '${_className(options.prefix, x)} *');
field, root.classes, _objcTypeForDartType,
customResolver: (String x) => '${_className(options.prefix, x)} *');
final String propertyType = hostDatatype.isBuiltin
? _propertyTypeForDartType(field.dataType)
: 'strong';
Expand Down
2 changes: 2 additions & 0 deletions packages/pigeon/pigeons/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import 'package:pigeon/pigeon_lib.dart';

class SearchRequest {
String query;
int anInt;
bool aBool;
}

class SearchReply {
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: pigeon
version: 0.1.0-experimental.3
version: 0.1.0-experimental.4
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
homepage: https://github.com/flutter/packages/tree/master/packages/pigeon
dependencies:
Expand Down

0 comments on commit bbdaf80

Please sign in to comment.