Skip to content

Commit

Permalink
[Pigeon] Fixed runtime exception with small values of int on Android. (
Browse files Browse the repository at this point in the history
  • Loading branch information
gaaclarke authored Mar 20, 2020
1 parent bbdaf80 commit 5cbb850
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
5 changes: 5 additions & 0 deletions packages/pigeon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.1.0-experimental.5

* Fixed runtime exception in Android with values of ints less than 2^32.
* Incremented codegen version warning.

## 0.1.0-experimental.4

* Fixed primitive types for Android Java.
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/lib/generator_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'dart:io';
import 'ast.dart';

/// The current version of pigeon.
const String pigeonVersion = '0.1.0-experimental.3';
const String pigeonVersion = '0.1.0-experimental.5';

/// Read all the content from [stdin] to a String.
String readStdin() {
Expand Down
15 changes: 12 additions & 3 deletions packages/pigeon/lib/java_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,17 @@ String _javaTypeForDartType(String datatype) {
return _javaTypeForDartTypeMap[datatype];
}

String _mapGetter(Field field, List<Class> classes, String mapName) {
final HostDatatype hostDatatype =
getHostDatatype(field, classes, _javaTypeForDartType);
final String result = '$mapName.get("${field.name}")';
if (field.dataType == 'int') {
return '($result instanceof Integer) ? (Integer)$result : (${hostDatatype.datatype})$result';
} else {
return '(${hostDatatype.datatype})$result';
}
}

/// Generates the ".java" file for the AST represented by [root] to [sink] with the
/// provided [options].
void generateJava(JavaOptions options, Root root, StringSink sink) {
Expand Down Expand Up @@ -197,10 +208,8 @@ 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} = (${hostDatatype.datatype})map.get("${field.name}");');
'fromMapResult.${field.name} = ${_mapGetter(field, root.classes, 'map')};');
}
indent.writeln('return fromMapResult;');
});
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.4
version: 0.1.0-experimental.5
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 5cbb850

Please sign in to comment.