Skip to content
Closed

ignore #10232

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
eb7cac6
methods, basic types, sync, nullable-sync, async, and classes
tarrinneal Apr 15, 2025
9fa695d
broken nullable async methods
tarrinneal Apr 15, 2025
0aff0fd
refactor type logic, add codec
tarrinneal Apr 17, 2025
1ed8a8b
objects and enums
tarrinneal Apr 22, 2025
ee50607
full codec
tarrinneal May 9, 2025
4c6eb1a
error handling and more tests
tarrinneal May 29, 2025
f87efd4
fix codec
tarrinneal May 29, 2025
3e9d9f0
flutter api and plumbing through legacy apis and tests
tarrinneal Jun 27, 2025
6ad2e37
jnigen.yaml
tarrinneal Jun 27, 2025
9b55d44
ffi just getting started
tarrinneal Jul 7, 2025
25e8c30
gen fluff
tarrinneal Jul 11, 2025
df40332
not working
tarrinneal Jul 16, 2025
d90ecca
missing files
tarrinneal Jul 17, 2025
92933f8
gitignore
tarrinneal Jul 17, 2025
cb1c0fe
ios ffigen settings
tarrinneal Jul 17, 2025
a7cc7ce
remove macos min version from ffigen config
tarrinneal Jul 17, 2025
8fb8dca
no dylibs
tarrinneal Jul 17, 2025
ab64302
more basic, still can't see class
tarrinneal Jul 17, 2025
c7d00c6
upload macos
tarrinneal Jul 17, 2025
33f8fa1
fix ffigen files
tarrinneal Jul 17, 2025
4977cc2
test
tarrinneal Jul 29, 2025
586edf2
wip
tarrinneal Jul 29, 2025
74b1cb1
Merge branch 'Frillback' of github.com:tarrinneal/packages into Frill…
tarrinneal Jul 29, 2025
3736528
ns
tarrinneal Jul 29, 2025
31d182f
dunno
tarrinneal Jul 30, 2025
c63e598
something
tarrinneal Jul 30, 2025
6dc23e7
working again
tarrinneal Jul 30, 2025
982dfe6
Merge branch 'Frillback' of https://github.com/tarrinneal/packages in…
tarrinneal Jul 30, 2025
ecc088a
enums
tarrinneal Aug 12, 2025
927fd8d
and this one
tarrinneal Aug 12, 2025
877d60d
ffi support for classes, enums, and objects (partial testing)
tarrinneal Aug 26, 2025
910ac95
tests
tarrinneal Aug 26, 2025
b522d6c
fix enums, still need to resolve Any?
tarrinneal Sep 4, 2025
bd47b34
actually fix enums
tarrinneal Sep 5, 2025
4192a89
starting nullables, gonna be a mess
tarrinneal Sep 5, 2025
86e6907
nullable base types in classes
tarrinneal Sep 17, 2025
87f4f8a
add nullable enums (no tests for null things though.....)
tarrinneal Sep 18, 2025
ed3eb93
update to latest version
tarrinneal Sep 19, 2025
457edef
Not even I understand
tarrinneal Sep 24, 2025
9214479
fix null object?
tarrinneal Sep 25, 2025
aadd859
multi-arity and nullable enums in classes
tarrinneal Sep 26, 2025
8cb24b6
nested classes
tarrinneal Sep 27, 2025
d29e86a
typed lists and maps except int keys
tarrinneal Oct 14, 2025
b32d506
Merge branch 'main' of https://github.com/flutter/packages into Frill…
tarrinneal Oct 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
objects and enums
  • Loading branch information
tarrinneal committed Apr 22, 2025
commit 1ed8a8b36dfa1c0a769a13a2efd5816e24cbd9cf
2 changes: 1 addition & 1 deletion packages/pigeon/example/app/lib/src/messages.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ bool _deepEquals(Object? a, Object? b) {

enum Code {
one,
two,
two;
}

class MessageData {
Expand Down
15 changes: 9 additions & 6 deletions packages/pigeon/lib/src/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -545,35 +545,38 @@ class TypeDeclaration {

/// Returns duplicated `TypeDeclaration` with attached `associatedEnum` value.
TypeDeclaration copyWithEnum(Enum enumDefinition) {
enumDefinition.associatedType = this;
return TypeDeclaration(
final TypeDeclaration newType = TypeDeclaration(
baseName: baseName,
isNullable: isNullable,
associatedEnum: enumDefinition,
typeArguments: typeArguments,
);
enumDefinition.associatedType = newType;
return newType;
}

/// Returns duplicated `TypeDeclaration` with attached `associatedClass` value.
TypeDeclaration copyWithClass(Class classDefinition) {
classDefinition.associatedType = this;
return TypeDeclaration(
final TypeDeclaration newType = TypeDeclaration(
baseName: baseName,
isNullable: isNullable,
associatedClass: classDefinition,
typeArguments: typeArguments,
);
classDefinition.associatedType = newType;
return newType;
}

/// Returns duplicated `TypeDeclaration` with attached `associatedProxyApi` value.
TypeDeclaration copyWithProxyApi(AstProxyApi proxyApiDefinition) {
proxyApiDefinition.associatedType = this;
return TypeDeclaration(
final TypeDeclaration newType = TypeDeclaration(
baseName: baseName,
isNullable: isNullable,
associatedProxyApi: proxyApiDefinition,
typeArguments: typeArguments,
);
proxyApiDefinition.associatedType = newType;
return newType;
}

/// Returns duplicated `TypeDeclaration` with attached `associatedProxyApi` value.
Expand Down
109 changes: 81 additions & 28 deletions packages/pigeon/lib/src/dart/dart_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,27 +130,62 @@ class _JniType {
);
}
_JniType? jniType = _jniTypeForDartType[type.baseName];
jniType = jniType ??
if (type.isClass) {
jniType = jniType ??
_JniType(
typeName: type.baseName,
jniName: 'bridge.${type.baseName}',
getToDartCall: (
TypeDeclaration type, {
String? varName,
bool forceConversion = false,
}) =>
'${type.baseName}.fromJni($varName)${_getForceNonNullSymbol(!type.isNullable)}',
getToJniCall: (
NamedType field,
_JniType jniType, {
bool forceNonNull = false,
}) =>
_wrapInNullCheckIfNullable(
field.type, field.name, '${field.name}.toJni()'),
isBuiltIn: false,
nonNullableNeedsUnwrapping: true,
);
} else if (type.isEnum) {
jniType = jniType ??
_JniType(
typeName: type.baseName,
jniName: 'bridge.${type.baseName}',
getToDartCall: (
TypeDeclaration type, {
String? varName,
bool forceConversion = false,
}) =>
'${type.baseName}.fromJni($varName)${_getForceNonNullSymbol(!type.isNullable)}',
getToJniCall: (
NamedType field,
_JniType jniType, {
bool forceNonNull = false,
}) =>
_wrapInNullCheckIfNullable(field.type, field.name,
'${field.name}${_getForceNonNullSymbol(type.isNullable && forceNonNull)}.toJni()'),
isBuiltIn: false,
nonNullableNeedsUnwrapping: true,
);
}
return jniType ??
_JniType(
typeName: type.baseName,
jniName: 'bridge.${type.baseName}',
getToDartCall: (
TypeDeclaration type, {
String? varName,
bool forceConversion = false,
}) =>
'${type.baseName}.fromJni($varName)${_getForceNonNullSymbol(!type.isNullable)}',
getToJniCall: (
NamedType field,
_JniType jniType, {
bool forceNonNull = false,
}) =>
_wrapInNullCheckIfNullable(
field.type, field.name, '${field.name}.toJni()'),
isBuiltIn: false,
nonNullableNeedsUnwrapping: true,
);
return jniType;
typeName: '',
jniName: '',
isBuiltIn: false,
getToDartCall:
(_, {bool forceConversion = true, String varName = ''}) => '',
getToJniCall: (
_,
__, {
bool forceNonNull = true,
}) =>
'');
}

final String typeName;
Expand Down Expand Up @@ -324,13 +359,13 @@ final Map<String, _JniType> _jniTypeForDartType = <String, _JniType>{
String varName = '',
bool forceConversion = false,
}) =>
'_PigeonJniCodec.readValue($varName)',
'_PigeonJniCodec.readValue($varName)${_getForceNonNullSymbol(!type.isNullable)}',
getToJniCall: (
NamedType field,
_JniType jniType, {
bool forceNonNull = false,
}) =>
'_PigeonJniCodec.writeValue(${field.name})',
'_PigeonJniCodec.writeValue(${field.name})${_getForceNonNullSymbol(!field.type.isNullable)}',
isBuiltIn: true,
nonNullableNeedsUnwrapping: true,
),
Expand Down Expand Up @@ -433,12 +468,30 @@ class DartGenerator extends StructuredGenerator<InternalDartOptions> {
indent.newln();
addDocumentationComments(
indent, anEnum.documentationComments, _docCommentSpec);
indent.write('enum ${anEnum.name} ');
indent.addScoped('{', '}', () {
indent.addScoped('enum ${anEnum.name} {', '}', () {
for (final EnumMember member in anEnum.members) {
final String separatorSymbol =
member == anEnum.members.last ? ';' : ',';
addDocumentationComments(
indent, member.documentationComments, _docCommentSpec);
indent.writeln('${member.name},');
indent.writeln('${member.name}$separatorSymbol');
}

if (generatorOptions.useJni) {
final _JniType jniType =
_JniType.fromTypeDeclaration(anEnum.associatedType);
indent.newln();
indent.writeScoped('${jniType.jniName} toJni() {', '}', () {
indent.writeln('return ${jniType.jniName}.Companion.ofRaw(index)!;');
});

indent.newln();
indent.writeScoped(
'static ${anEnum.name}? fromJni(${jniType.jniName}? jniEnum) {',
'}', () {
indent.writeln(
'return jniEnum == null ? null : ${anEnum.name}.values[jniEnum.getRaw()];');
});
}
});
}
Expand Down Expand Up @@ -574,7 +627,7 @@ class DartGenerator extends StructuredGenerator<InternalDartOptions> {
in getFieldsInSerializationOrder(classDefinition)) {
final _JniType jniType = _JniType.fromTypeDeclaration(field.type);
indent.writeln(
'${field.name}: jniClass.${jniType.getJniGetterMethodName(field.name)}${jniType.getToDartCall(field.type)},');
'${field.name}: ${jniType.getToDartCall(field.type, varName: 'jniClass.${jniType.getJniGetterMethodName(field.name)}')},');
}
});
});
Expand Down Expand Up @@ -1486,7 +1539,7 @@ final BinaryMessenger? ${varNamePrefix}binaryMessenger;
indent.newln();
indent.format('''
class _PigeonJniCodec {
Object? readValue(JObject? value) {
static Object? readValue(JObject? value) {
if (value == null) {
return null;
} else if (value.isA<JLong>(JLong.type)) {
Expand Down Expand Up @@ -1527,7 +1580,7 @@ class _PigeonJniCodec {
}
}

JObject? writeValue(Object? value) {
static JObject? writeValue(Object? value) {
if (value == null) {
return null;
} else if (value is bool) {
Expand Down
3 changes: 3 additions & 0 deletions packages/pigeon/lib/src/kotlin/jnigen_yaml_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class JnigenYamlGenerator extends Generator<InternalJnigenYamlOptions> {
for (final Class dataClass in root.classes) {
indent.writeln("- '${dataClass.name}'");
}
for (final Enum enumType in root.enums) {
indent.writeln("- '${enumType.name}'");
}
});
}
}
28 changes: 24 additions & 4 deletions packages/pigeon/pigeons/jni_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,36 @@ import 'package:pigeon/pigeon.dart';
dartOptions: DartOptions(useJni: true),
kotlinOptions: KotlinOptions(useJni: true),
))
enum SomeEnum {
value1,
value2,
value3,
}

class SomeTypes {
const SomeTypes(
this.aString,
this.anInt,
this.aDouble,
this.aBool,
// this.anObject,
this.anObject,
this.anEnum,
);
final String aString;
final int anInt;
final double aDouble;
final bool aBool;
// final Object anObject;
final Object anObject;
final SomeEnum anEnum;
}

class SomeNullableTypes {
String? aString;
int? anInt;
double? aDouble;
bool? aBool;
// Object? anObject;
Object? anObject;
SomeEnum? anEnum;
}

@HostApi()
Expand All @@ -38,8 +47,9 @@ abstract class JniMessageApi {
int echoInt(int request);
double echoDouble(double request);
bool echoBool(bool request);
// Object echoObj(Object request);
Object echoObj(Object request);
SomeTypes sendSomeTypes(SomeTypes someTypes);
SomeEnum sendSomeEnum(SomeEnum anEnum);
}

@HostApi()
Expand All @@ -48,7 +58,9 @@ abstract class JniMessageApiNullable {
int? echoInt(int? request);
double? echoDouble(double? request);
bool? echoBool(bool? request);
Object? echoObj(Object? request);
SomeNullableTypes? sendSomeNullableTypes(SomeNullableTypes? someTypes);
SomeEnum? sendSomeEnum(SomeEnum? anEnum);
}

@HostApi()
Expand All @@ -64,7 +76,11 @@ abstract class JniMessageApiAsync {
@async
bool echoBool(bool request);
@async
Object echoObj(Object request);
@async
SomeTypes sendSomeTypes(SomeTypes someTypes);
@async
SomeEnum sendSomeEnum(SomeEnum anEnum);
}

@HostApi()
Expand All @@ -78,5 +94,9 @@ abstract class JniMessageApiNullableAsync {
@async
bool? echoBool(bool? request);
@async
Object? echoObj(Object? request);
@async
SomeNullableTypes? sendSomeNullableTypes(SomeNullableTypes? someTypes);
@async
SomeEnum? sendSomeEnum(SomeEnum? anEnum);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'package:flutter/material.dart';

import 'generated.dart';
import 'src/generated/jni_tests.gen.dart';

void main() {
runApp(const ExampleApp());
Expand Down Expand Up @@ -39,6 +40,18 @@ class _ExampleAppState extends State<ExampleApp> {
// Make a single trivial call just to validate that everything is wired
// up.
await api.noop();
final JniMessageApi? jniMessage = JniMessageApi.getInstance();
print('before sendSomeTypes');
final SomeTypes toSend = SomeTypes(
aString: 'hi',
anInt: 5,
aDouble: 5.0,
aBool: false,
anObject: 'obj',
anEnum: SomeEnum.value2,
);
final SomeTypes sync = jniMessage!.sendSomeTypes(toSend);
print(sync);
} catch (e) {
setState(() {
status = 'Failed: $e';
Expand Down
Loading