From e7d9f835d6c15c72778606fd97fe24ea2a234e96 Mon Sep 17 00:00:00 2001 From: Hossein Yousefi Date: Mon, 25 Nov 2024 20:52:05 +0100 Subject: [PATCH 01/13] Parse all Kotlin metadata --- .../apisummarizer/elements/KotlinType.java | 5 + pkgs/jnigen/lib/src/elements/elements.dart | 233 +++++++++++++++++- pkgs/jnigen/lib/src/elements/elements.g.dart | 180 +++++++++++--- 3 files changed, 378 insertions(+), 40 deletions(-) diff --git a/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/elements/KotlinType.java b/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/elements/KotlinType.java index 8e91122ef..6ed80d741 100644 --- a/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/elements/KotlinType.java +++ b/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/elements/KotlinType.java @@ -6,6 +6,8 @@ import java.util.List; import java.util.stream.Collectors; + +import kotlinx.metadata.Flag; import kotlinx.metadata.KmClassifier; import kotlinx.metadata.KmType; @@ -15,11 +17,14 @@ public class KotlinType { public String name; public int id; public List arguments; + public boolean isNullable; public static KotlinType fromKmType(KmType t) { if (t == null) return null; var type = new KotlinType(); type.flags = t.getFlags(); + // Processing the information needed from the flags. + type.isNullable = Flag.Type.IS_NULLABLE.invoke(type.flags); var classifier = t.getClassifier(); if (classifier instanceof KmClassifier.Class) { type.kind = "class"; diff --git a/pkgs/jnigen/lib/src/elements/elements.dart b/pkgs/jnigen/lib/src/elements/elements.dart index 9ab4aa720..469faa013 100644 --- a/pkgs/jnigen/lib/src/elements/elements.dart +++ b/pkgs/jnigen/lib/src/elements/elements.dart @@ -21,9 +21,8 @@ abstract class Element> { R accept(Visitor v); } -@JsonEnum() - /// A kind describes the type of a declaration. +@JsonEnum() enum DeclKind { @JsonValue('CLASS') classKind, @@ -915,11 +914,39 @@ class Annotation implements Element { class KotlinClass implements Element { KotlinClass({ required this.name, - this.functions = const [], + required this.moduleName, + required this.functions, + required this.properties, + required this.constructors, + required this.typeParameters, + required this.contextReceiverTypes, + required this.superTypes, + required this.nestedClasses, + required this.enumEntries, + required this.sealedClasses, + required this.companionObject, + required this.inlineClassUnderlyingPropertyName, + required this.inlineClassUnderlyingType, + required this.flags, + required this.jvmFlags, }); final String name; + final String moduleName; final List functions; + final List properties; + final List constructors; + final List typeParameters; + final List contextReceiverTypes; + final List superTypes; + final List nestedClasses; + final List enumEntries; + final List sealedClasses; + final String companionObject; + final String inlineClassUnderlyingPropertyName; + final KotlinType inlineClassUnderlyingType; + final int flags; + final int jvmFlags; factory KotlinClass.fromJson(Map json) => _$KotlinClassFromJson(json); @@ -948,28 +975,216 @@ class KotlinPackage implements Element { } @JsonSerializable(createToJson: false) -class KotlinFunction implements Element { +class KotlinFunction { KotlinFunction({ required this.name, required this.descriptor, required this.kotlinName, + required this.valueParameters, + required this.returnType, + required this.receiverParameterType, + required this.contextReceiverTypes, + required this.typeParameters, + required this.flags, required this.isSuspend, }); + /// Name in the byte code. final String name; - - /// Used to match with [Method]'s descriptor. - /// - /// Creates a unique signature in combination with [name]. final String descriptor; + + /// Name in the Kotlin's metadata. final String kotlinName; + + final List valueParameters; + final KotlinType returnType; + final KotlinType receiverParameterType; + final List contextReceiverTypes; + final List typeParameters; + final int flags; final bool isSuspend; factory KotlinFunction.fromJson(Map json) => _$KotlinFunctionFromJson(json); +} + +@JsonSerializable(createToJson: false) +class KotlinConstructor implements Element { + KotlinConstructor({ + required this.name, + required this.descriptor, + required this.valueParameters, + required this.flags, + }); + + final String name; + final String descriptor; + final List valueParameters; + final int flags; + + factory KotlinConstructor.fromJson(Map json) => + _$KotlinConstructorFromJson(json); + + @override + R accept(Visitor v) { + return v.visit(this); + } +} + +@JsonSerializable(createToJson: false) +class KotlinProperty implements Element { + KotlinProperty({ + required this.fieldName, + required this.fieldDescriptor, + required this.getterName, + required this.getterDescriptor, + required this.setterName, + required this.setterDescriptor, + required this.kotlinName, + required this.returnType, + required this.receiverParameterType, + required this.contextReceiverTypes, + required this.jvmFlags, + required this.flags, + required this.setterFlags, + required this.getterFlags, + required this.typeParameters, + required this.setterParameter, + }); + + final String fieldName; + final String fieldDescriptor; + + /// Getter's name in the byte code. + final String getterName; + final String getterDescriptor; + + /// Setter's name in the byte code. + final String setterName; + final String setterDescriptor; + + /// Name in the Kotlin's metadata. + final String kotlinName; + + final KotlinType returnType; + final KotlinType receiverParameterType; + final List contextReceiverTypes; + final int jvmFlags; + final int flags; + final int setterFlags; + final int getterFlags; + final List typeParameters; + final KotlinValueParameter setterParameter; + + factory KotlinProperty.fromJson(Map json) => + _$KotlinPropertyFromJson(json); + + @override + R accept(Visitor v) { + return v.visit(this); + } +} + +@JsonSerializable(createToJson: false) +class KotlinType implements Element { + KotlinType({ + required this.flags, + required this.kind, + required this.name, + required this.id, + required this.arguments, + required this.isNullable, + }); + + final int flags; + final String kind; + final String name; + final int id; + final List arguments; + final bool isNullable; + + factory KotlinType.fromJson(Map json) => + _$KotlinTypeFromJson(json); + + @override + R accept(Visitor v) { + return v.visit(this); + } +} + +@JsonEnum() +enum KmVariance { + @JsonValue('INVARIANT') + invariant, + @JsonValue('IN') + contravariant, + @JsonValue('OUT') + covariant, +} + +@JsonSerializable(createToJson: false) +class KotlinTypeParameter implements Element { + KotlinTypeParameter({ + required this.name, + required this.id, + required this.flags, + required this.upperBounds, + required this.variance, + }); + + final String name; + final int id; + final int flags; + final List upperBounds; + final KmVariance variance; + + factory KotlinTypeParameter.fromJson(Map json) => + _$KotlinTypeParameterFromJson(json); + + @override + R accept(Visitor v) { + return v.visit(this); + } +} + +@JsonSerializable(createToJson: false) +class KotlinValueParameter implements Element { + KotlinValueParameter({ + required this.name, + required this.flags, + required this.type, + required this.varargElementType, + }); + + final String name; + final int flags; + final KotlinType type; + final KotlinType varargElementType; + + factory KotlinValueParameter.fromJson(Map json) => + _$KotlinValueParameterFromJson(json); + + @override + R accept(Visitor v) { + return v.visit(this); + } +} + +@JsonSerializable(createToJson: false) +class KotlinTypeProjection implements Element { + KotlinTypeProjection({ + required this.type, + required this.variance, + }); + + final KotlinType type; + final KmVariance variance; + + factory KotlinTypeProjection.fromJson(Map json) => + _$KotlinTypeProjectionFromJson(json); @override - R accept(Visitor v) { + R accept(Visitor v) { return v.visit(this); } } diff --git a/pkgs/jnigen/lib/src/elements/elements.g.dart b/pkgs/jnigen/lib/src/elements/elements.g.dart index e981d2054..4616ef26f 100644 --- a/pkgs/jnigen/lib/src/elements/elements.g.dart +++ b/pkgs/jnigen/lib/src/elements/elements.g.dart @@ -8,9 +8,8 @@ part of 'elements.dart'; ClassDecl _$ClassDeclFromJson(Map json) => ClassDecl( annotations: (json['annotations'] as List?) - ?.map((e) => Annotation.fromJson(e as Map)) - .toList() ?? - const [], + ?.map((e) => Annotation.fromJson(e as Map)) + .toList(), javadoc: json['javadoc'] == null ? null : JavaDocComment.fromJson(json['javadoc'] as Map), @@ -76,9 +75,8 @@ const _$KindEnumMap = { DeclaredType _$DeclaredTypeFromJson(Map json) => DeclaredType( binaryName: json['binaryName'] as String, annotations: (json['annotations'] as List?) - ?.map((e) => Annotation.fromJson(e as Map)) - .toList() ?? - const [], + ?.map((e) => Annotation.fromJson(e as Map)) + .toList(), params: (json['params'] as List?) ?.map((e) => TypeUsage.fromJson(e as Map)) .toList() ?? @@ -88,9 +86,8 @@ DeclaredType _$DeclaredTypeFromJson(Map json) => DeclaredType( TypeVar _$TypeVarFromJson(Map json) => TypeVar( name: json['name'] as String, annotations: (json['annotations'] as List?) - ?.map((e) => Annotation.fromJson(e as Map)) - .toList() ?? - const [], + ?.map((e) => Annotation.fromJson(e as Map)) + .toList(), ); Wildcard _$WildcardFromJson(Map json) => Wildcard( @@ -101,25 +98,22 @@ Wildcard _$WildcardFromJson(Map json) => Wildcard( ? null : TypeUsage.fromJson(json['superBound'] as Map), annotations: (json['annotations'] as List?) - ?.map((e) => Annotation.fromJson(e as Map)) - .toList() ?? - const [], + ?.map((e) => Annotation.fromJson(e as Map)) + .toList(), ); ArrayType _$ArrayTypeFromJson(Map json) => ArrayType( elementType: TypeUsage.fromJson(json['elementType'] as Map), annotations: (json['annotations'] as List?) - ?.map((e) => Annotation.fromJson(e as Map)) - .toList() ?? - const [], + ?.map((e) => Annotation.fromJson(e as Map)) + .toList(), ); Method _$MethodFromJson(Map json) => Method( annotations: (json['annotations'] as List?) - ?.map((e) => Annotation.fromJson(e as Map)) - .toList() ?? - const [], + ?.map((e) => Annotation.fromJson(e as Map)) + .toList(), javadoc: json['javadoc'] == null ? null : JavaDocComment.fromJson(json['javadoc'] as Map), @@ -143,9 +137,8 @@ Method _$MethodFromJson(Map json) => Method( Param _$ParamFromJson(Map json) => Param( annotations: (json['annotations'] as List?) - ?.map((e) => Annotation.fromJson(e as Map)) - .toList() ?? - const [], + ?.map((e) => Annotation.fromJson(e as Map)) + .toList(), javadoc: json['javadoc'] == null ? null : JavaDocComment.fromJson(json['javadoc'] as Map), @@ -155,9 +148,8 @@ Param _$ParamFromJson(Map json) => Param( Field _$FieldFromJson(Map json) => Field( annotations: (json['annotations'] as List?) - ?.map((e) => Annotation.fromJson(e as Map)) - .toList() ?? - const [], + ?.map((e) => Annotation.fromJson(e as Map)) + .toList(), javadoc: json['javadoc'] == null ? null : JavaDocComment.fromJson(json['javadoc'] as Map), @@ -177,9 +169,8 @@ TypeParam _$TypeParamFromJson(Map json) => TypeParam( .toList() ?? const [], annotations: (json['annotations'] as List?) - ?.map((e) => Annotation.fromJson(e as Map)) - .toList() ?? - const [], + ?.map((e) => Annotation.fromJson(e as Map)) + .toList(), ); JavaDocComment _$JavaDocCommentFromJson(Map json) => @@ -200,10 +191,41 @@ Annotation _$AnnotationFromJson(Map json) => Annotation( KotlinClass _$KotlinClassFromJson(Map json) => KotlinClass( name: json['name'] as String, - functions: (json['functions'] as List?) - ?.map((e) => KotlinFunction.fromJson(e as Map)) - .toList() ?? - const [], + moduleName: json['moduleName'] as String, + functions: (json['functions'] as List) + .map((e) => KotlinFunction.fromJson(e as Map)) + .toList(), + properties: (json['properties'] as List) + .map((e) => KotlinProperty.fromJson(e as Map)) + .toList(), + constructors: (json['constructors'] as List) + .map((e) => KotlinConstructor.fromJson(e as Map)) + .toList(), + typeParameters: (json['typeParameters'] as List) + .map((e) => KotlinTypeParameter.fromJson(e as Map)) + .toList(), + contextReceiverTypes: (json['contextReceiverTypes'] as List) + .map((e) => KotlinType.fromJson(e as Map)) + .toList(), + superTypes: (json['superTypes'] as List) + .map((e) => KotlinType.fromJson(e as Map)) + .toList(), + nestedClasses: (json['nestedClasses'] as List) + .map((e) => e as String) + .toList(), + enumEntries: (json['enumEntries'] as List) + .map((e) => e as String) + .toList(), + sealedClasses: (json['sealedClasses'] as List) + .map((e) => e as String) + .toList(), + companionObject: json['companionObject'] as String, + inlineClassUnderlyingPropertyName: + json['inlineClassUnderlyingPropertyName'] as String, + inlineClassUnderlyingType: KotlinType.fromJson( + json['inlineClassUnderlyingType'] as Map), + flags: (json['flags'] as num).toInt(), + jvmFlags: (json['jvmFlags'] as num).toInt(), ); KotlinPackage _$KotlinPackageFromJson(Map json) => @@ -219,5 +241,101 @@ KotlinFunction _$KotlinFunctionFromJson(Map json) => name: json['name'] as String, descriptor: json['descriptor'] as String, kotlinName: json['kotlinName'] as String, + valueParameters: (json['valueParameters'] as List) + .map((e) => KotlinValueParameter.fromJson(e as Map)) + .toList(), + returnType: + KotlinType.fromJson(json['returnType'] as Map), + receiverParameterType: KotlinType.fromJson( + json['receiverParameterType'] as Map), + contextReceiverTypes: (json['contextReceiverTypes'] as List) + .map((e) => KotlinType.fromJson(e as Map)) + .toList(), + typeParameters: (json['typeParameters'] as List) + .map((e) => KotlinTypeParameter.fromJson(e as Map)) + .toList(), + flags: (json['flags'] as num).toInt(), isSuspend: json['isSuspend'] as bool, ); + +KotlinConstructor _$KotlinConstructorFromJson(Map json) => + KotlinConstructor( + name: json['name'] as String, + descriptor: json['descriptor'] as String, + valueParameters: (json['valueParameters'] as List) + .map((e) => KotlinValueParameter.fromJson(e as Map)) + .toList(), + flags: (json['flags'] as num).toInt(), + ); + +KotlinProperty _$KotlinPropertyFromJson(Map json) => + KotlinProperty( + fieldName: json['fieldName'] as String, + fieldDescriptor: json['fieldDescriptor'] as String, + getterName: json['getterName'] as String, + getterDescriptor: json['getterDescriptor'] as String, + setterName: json['setterName'] as String, + setterDescriptor: json['setterDescriptor'] as String, + kotlinName: json['kotlinName'] as String, + returnType: + KotlinType.fromJson(json['returnType'] as Map), + receiverParameterType: KotlinType.fromJson( + json['receiverParameterType'] as Map), + contextReceiverTypes: (json['contextReceiverTypes'] as List) + .map((e) => KotlinType.fromJson(e as Map)) + .toList(), + jvmFlags: (json['jvmFlags'] as num).toInt(), + flags: (json['flags'] as num).toInt(), + setterFlags: (json['setterFlags'] as num).toInt(), + getterFlags: (json['getterFlags'] as num).toInt(), + typeParameters: (json['typeParameters'] as List) + .map((e) => KotlinTypeParameter.fromJson(e as Map)) + .toList(), + setterParameter: KotlinValueParameter.fromJson( + json['setterParameter'] as Map), + ); + +KotlinType _$KotlinTypeFromJson(Map json) => KotlinType( + flags: (json['flags'] as num).toInt(), + kind: json['kind'] as String, + name: json['name'] as String, + id: (json['id'] as num).toInt(), + arguments: (json['arguments'] as List) + .map((e) => KotlinTypeProjection.fromJson(e as Map)) + .toList(), + isNullable: json['isNullable'] as bool, + ); + +KotlinTypeParameter _$KotlinTypeParameterFromJson(Map json) => + KotlinTypeParameter( + name: json['name'] as String, + id: (json['id'] as num).toInt(), + flags: (json['flags'] as num).toInt(), + upperBounds: (json['upperBounds'] as List) + .map((e) => KotlinType.fromJson(e as Map)) + .toList(), + variance: $enumDecode(_$KmVarianceEnumMap, json['variance']), + ); + +const _$KmVarianceEnumMap = { + KmVariance.invariant: 'INVARIANT', + KmVariance.contravariant: 'IN', + KmVariance.covariant: 'OUT', +}; + +KotlinValueParameter _$KotlinValueParameterFromJson( + Map json) => + KotlinValueParameter( + name: json['name'] as String, + flags: (json['flags'] as num).toInt(), + type: KotlinType.fromJson(json['type'] as Map), + varargElementType: KotlinType.fromJson( + json['varargElementType'] as Map), + ); + +KotlinTypeProjection _$KotlinTypeProjectionFromJson( + Map json) => + KotlinTypeProjection( + type: KotlinType.fromJson(json['type'] as Map), + variance: $enumDecode(_$KmVarianceEnumMap, json['variance']), + ); From 55a26bf33cc2fd13911201c7bdab34bc33d47bd5 Mon Sep 17 00:00:00 2001 From: Hossein Yousefi Date: Wed, 27 Nov 2024 20:12:17 +0100 Subject: [PATCH 02/13] Add nullability annotation from Kotlin metadata --- .../apisummarizer/elements/KotlinPackage.java | 3 + .../elements/KotlinTypeParameter.java | 2 + .../lib/src/bindings/kotlin_processor.dart | 171 +++- pkgs/jnigen/lib/src/elements/elements.dart | 78 +- pkgs/jnigen/lib/src/elements/elements.g.dart | 178 +++-- .../test/kotlin_test/bindings/kotlin.dart | 740 +++++++++++++++++- .../com/github/dart_lang/jnigen/Nullabilty.kt | 31 + .../kotlin_test/runtime_test_registrant.dart | 2 +- 8 files changed, 1068 insertions(+), 137 deletions(-) create mode 100644 pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullabilty.kt diff --git a/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/elements/KotlinPackage.java b/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/elements/KotlinPackage.java index 5252e0071..3610a18aa 100644 --- a/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/elements/KotlinPackage.java +++ b/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/elements/KotlinPackage.java @@ -6,11 +6,14 @@ public class KotlinPackage { public List functions; + public List properties; public static KotlinPackage fromKmPackage(KmPackage p) { var pkg = new KotlinPackage(); pkg.functions = p.getFunctions().stream().map(KotlinFunction::fromKmFunction).collect(Collectors.toList()); + pkg.properties = + p.getProperties().stream().map(KotlinProperty::fromKmProperty).collect(Collectors.toList()); return pkg; } } diff --git a/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/elements/KotlinTypeParameter.java b/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/elements/KotlinTypeParameter.java index 449aef16c..74f94afe8 100644 --- a/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/elements/KotlinTypeParameter.java +++ b/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/elements/KotlinTypeParameter.java @@ -6,6 +6,8 @@ import java.util.List; import java.util.stream.Collectors; + +import kotlinx.metadata.Flag; import kotlinx.metadata.KmTypeParameter; import kotlinx.metadata.KmVariance; diff --git a/pkgs/jnigen/lib/src/bindings/kotlin_processor.dart b/pkgs/jnigen/lib/src/bindings/kotlin_processor.dart index 53de1ed2d..f8cd47798 100644 --- a/pkgs/jnigen/lib/src/bindings/kotlin_processor.dart +++ b/pkgs/jnigen/lib/src/bindings/kotlin_processor.dart @@ -24,6 +24,37 @@ class _KotlinClassProcessor extends Visitor { return; } // This [ClassDecl] is actually a Kotlin class. + if (node.kotlinClass != null) { + for (var i = 0; i < node.kotlinClass!.typeParameters.length; ++i) { + node.typeParams[i].accept( + _KotlinTypeParamProcessor(node.kotlinClass!.typeParameters[i])); + } + } + + // Matching fields and properties from the metadata. + final properties = {}; + final getters = {}; + final setters = {}; + final kotlinProperties = + (node.kotlinClass?.properties ?? node.kotlinPackage?.properties)!; + for (final property in kotlinProperties) { + if (property.fieldName case final fieldName?) { + properties[fieldName] = property; + } + if (property.getterName case final getterName?) { + final getterSignature = getterName + property.getterDescriptor!; + getters[getterSignature] = property; + } + if (property.setterName case final setterName?) { + final setterSignature = setterName + property.setterDescriptor!; + setters[setterSignature] = property; + } + } + for (final field in node.fields) { + if (properties[field.name] case final property?) { + field.accept(_KotlinPropertyProcessor(property)); + } + } // Matching methods and functions from the metadata. final functions = {}; final kotlinFunctions = @@ -32,15 +63,37 @@ class _KotlinClassProcessor extends Visitor { final signature = function.name + function.descriptor; functions[signature] = function; } + final constructors = {}; + final kotlinConstructors = node.kotlinClass?.constructors ?? []; + for (final constructor in kotlinConstructors) { + final signature = constructor.name + constructor.descriptor; + constructors[signature] = constructor; + } for (final method in node.methods) { final signature = method.name + method.descriptor!; - if (functions.containsKey(signature)) { - method.accept(_KotlinMethodProcessor(functions[signature]!)); + if (functions[signature] case final function?) { + method.accept(_KotlinMethodProcessor(function)); + } else if (constructors[signature] case final constructor?) { + method.accept(_KotlinConstructorProcessor(constructor)); + } else if (getters[signature] case final getter?) { + method.accept(_KotlinGetterProcessor(getter)); + } else if (setters[signature] case final setter?) { + method.accept(_KotlinSetterProcessor(setter)); } } } } +void _processParams( + List params, List kotlinParams) { + if (params.length != kotlinParams.length) { + return; + } + for (var i = 0; i < params.length; ++i) { + params[i].accept(_KotlinParamProcessor(kotlinParams[i])); + } +} + class _KotlinMethodProcessor extends Visitor { final KotlinFunction function; @@ -48,6 +101,8 @@ class _KotlinMethodProcessor extends Visitor { @override void visit(Method node) { + node.returnType.accept(_KotlinTypeProcessor(function.returnType)); + _processParams(node.params, function.valueParameters); if (function.isSuspend) { const kotlinContinutationType = 'kotlin.coroutines.Continuation'; assert(node.params.isNotEmpty && @@ -66,3 +121,115 @@ class _KotlinMethodProcessor extends Visitor { } } } + +class _KotlinConstructorProcessor extends Visitor { + final KotlinConstructor constructor; + + _KotlinConstructorProcessor(this.constructor); + + @override + void visit(Method node) { + _processParams(node.params, constructor.valueParameters); + } +} + +class _KotlinGetterProcessor extends Visitor { + final KotlinProperty getter; + + _KotlinGetterProcessor(this.getter); + + @override + void visit(Method node) { + node.returnType.accept(_KotlinTypeProcessor(getter.returnType)); + } +} + +class _KotlinSetterProcessor extends Visitor { + final KotlinProperty setter; + + _KotlinSetterProcessor(this.setter); + + @override + void visit(Method node) { + if (setter.setterParameter case final setterParam?) { + node.returnType.accept(_KotlinTypeProcessor(setterParam.type)); + } + node.returnType.accept(_KotlinTypeProcessor(setter.returnType)); + } +} + +class _KotlinPropertyProcessor extends Visitor { + final KotlinProperty property; + + _KotlinPropertyProcessor(this.property); + + @override + void visit(Field node) { + node.type.accept(_KotlinTypeProcessor(property.returnType)); + } +} + +class _KotlinParamProcessor extends Visitor { + final KotlinValueParameter kotlinParam; + + _KotlinParamProcessor(this.kotlinParam); + + @override + void visit(Param node) { + node.type.accept(_KotlinTypeProcessor(kotlinParam.type)); + } +} + +class _KotlinTypeParamProcessor extends Visitor { + final KotlinTypeParameter kotlinTypeParam; + + _KotlinTypeParamProcessor(this.kotlinTypeParam); + + @override + void visit(TypeParam node) { + final kotlinBounds = kotlinTypeParam.upperBounds; + final bounds = {}; + for (final bound in kotlinBounds) { + if (bound.name case final boundName?) { + bounds[boundName] = bound; + } + } + for (final bound in node.bounds) { + if (bounds[bound.name] case final kotlinBound?) { + bound.accept(_KotlinTypeProcessor(kotlinBound)); + } + } + } +} + +class _KotlinTypeProcessor extends TypeVisitor { + final KotlinType kotlinType; + + _KotlinTypeProcessor(this.kotlinType); + + @override + void visitDeclaredType(DeclaredType node) { + for (var i = 0; i < node.params.length; ++i) { + node.params[i].accept(_KotlinTypeProcessor(kotlinType.arguments[i].type)); + } + super.visitDeclaredType(node); + } + + @override + void visitArrayType(ArrayType node) { + node.elementType + .accept(_KotlinTypeProcessor(kotlinType.arguments.first.type)); + } + + @override + void visitNonPrimitiveType(ReferredType node) { + node.annotations ??= []; + node.annotations! + .add(kotlinType.isNullable ? Annotation.nullable : Annotation.nonNull); + } + + @override + void visitPrimitiveType(PrimitiveType node) { + // Do nothing. + } +} diff --git a/pkgs/jnigen/lib/src/elements/elements.dart b/pkgs/jnigen/lib/src/elements/elements.dart index 469faa013..cbdbea653 100644 --- a/pkgs/jnigen/lib/src/elements/elements.dart +++ b/pkgs/jnigen/lib/src/elements/elements.dart @@ -915,15 +915,15 @@ class KotlinClass implements Element { KotlinClass({ required this.name, required this.moduleName, - required this.functions, - required this.properties, - required this.constructors, - required this.typeParameters, - required this.contextReceiverTypes, - required this.superTypes, - required this.nestedClasses, - required this.enumEntries, - required this.sealedClasses, + this.functions = const [], + this.properties = const [], + this.constructors = const [], + this.typeParameters = const [], + this.contextReceiverTypes = const [], + this.superTypes = const [], + this.nestedClasses = const [], + this.enumEntries = const [], + this.sealedClasses = const [], required this.companionObject, required this.inlineClassUnderlyingPropertyName, required this.inlineClassUnderlyingType, @@ -942,9 +942,9 @@ class KotlinClass implements Element { final List nestedClasses; final List enumEntries; final List sealedClasses; - final String companionObject; - final String inlineClassUnderlyingPropertyName; - final KotlinType inlineClassUnderlyingType; + final String? companionObject; + final String? inlineClassUnderlyingPropertyName; + final KotlinType? inlineClassUnderlyingType; final int flags; final int jvmFlags; @@ -961,9 +961,11 @@ class KotlinClass implements Element { class KotlinPackage implements Element { KotlinPackage({ this.functions = const [], + this.properties = const [], }); final List functions; + final List properties; factory KotlinPackage.fromJson(Map json) => _$KotlinPackageFromJson(json); @@ -980,11 +982,11 @@ class KotlinFunction { required this.name, required this.descriptor, required this.kotlinName, - required this.valueParameters, + this.valueParameters = const [], required this.returnType, - required this.receiverParameterType, - required this.contextReceiverTypes, - required this.typeParameters, + this.receiverParameterType, + this.contextReceiverTypes = const [], + this.typeParameters = const [], required this.flags, required this.isSuspend, }); @@ -998,7 +1000,7 @@ class KotlinFunction { final List valueParameters; final KotlinType returnType; - final KotlinType receiverParameterType; + final KotlinType? receiverParameterType; final List contextReceiverTypes; final List typeParameters; final int flags; @@ -1013,7 +1015,7 @@ class KotlinConstructor implements Element { KotlinConstructor({ required this.name, required this.descriptor, - required this.valueParameters, + this.valueParameters = const [], required this.flags, }); @@ -1034,47 +1036,47 @@ class KotlinConstructor implements Element { @JsonSerializable(createToJson: false) class KotlinProperty implements Element { KotlinProperty({ - required this.fieldName, - required this.fieldDescriptor, - required this.getterName, - required this.getterDescriptor, - required this.setterName, - required this.setterDescriptor, + this.fieldName, + this.fieldDescriptor, + this.getterName, + this.getterDescriptor, + this.setterName, + this.setterDescriptor, required this.kotlinName, required this.returnType, required this.receiverParameterType, - required this.contextReceiverTypes, + this.contextReceiverTypes = const [], required this.jvmFlags, required this.flags, required this.setterFlags, required this.getterFlags, - required this.typeParameters, + this.typeParameters = const [], required this.setterParameter, }); - final String fieldName; - final String fieldDescriptor; + final String? fieldName; + final String? fieldDescriptor; /// Getter's name in the byte code. - final String getterName; - final String getterDescriptor; + final String? getterName; + final String? getterDescriptor; /// Setter's name in the byte code. - final String setterName; - final String setterDescriptor; + final String? setterName; + final String? setterDescriptor; /// Name in the Kotlin's metadata. final String kotlinName; final KotlinType returnType; - final KotlinType receiverParameterType; + final KotlinType? receiverParameterType; final List contextReceiverTypes; final int jvmFlags; final int flags; final int setterFlags; final int getterFlags; final List typeParameters; - final KotlinValueParameter setterParameter; + final KotlinValueParameter? setterParameter; factory KotlinProperty.fromJson(Map json) => _$KotlinPropertyFromJson(json); @@ -1092,13 +1094,13 @@ class KotlinType implements Element { required this.kind, required this.name, required this.id, - required this.arguments, required this.isNullable, + this.arguments = const [], }); final int flags; final String kind; - final String name; + final String? name; final int id; final List arguments; final bool isNullable; @@ -1128,7 +1130,7 @@ class KotlinTypeParameter implements Element { required this.name, required this.id, required this.flags, - required this.upperBounds, + this.upperBounds = const [], required this.variance, }); @@ -1159,7 +1161,7 @@ class KotlinValueParameter implements Element { final String name; final int flags; final KotlinType type; - final KotlinType varargElementType; + final KotlinType? varargElementType; factory KotlinValueParameter.fromJson(Map json) => _$KotlinValueParameterFromJson(json); diff --git a/pkgs/jnigen/lib/src/elements/elements.g.dart b/pkgs/jnigen/lib/src/elements/elements.g.dart index 4616ef26f..180741d65 100644 --- a/pkgs/jnigen/lib/src/elements/elements.g.dart +++ b/pkgs/jnigen/lib/src/elements/elements.g.dart @@ -192,38 +192,51 @@ Annotation _$AnnotationFromJson(Map json) => Annotation( KotlinClass _$KotlinClassFromJson(Map json) => KotlinClass( name: json['name'] as String, moduleName: json['moduleName'] as String, - functions: (json['functions'] as List) - .map((e) => KotlinFunction.fromJson(e as Map)) - .toList(), - properties: (json['properties'] as List) - .map((e) => KotlinProperty.fromJson(e as Map)) - .toList(), - constructors: (json['constructors'] as List) - .map((e) => KotlinConstructor.fromJson(e as Map)) - .toList(), - typeParameters: (json['typeParameters'] as List) - .map((e) => KotlinTypeParameter.fromJson(e as Map)) - .toList(), - contextReceiverTypes: (json['contextReceiverTypes'] as List) - .map((e) => KotlinType.fromJson(e as Map)) - .toList(), - superTypes: (json['superTypes'] as List) - .map((e) => KotlinType.fromJson(e as Map)) - .toList(), - nestedClasses: (json['nestedClasses'] as List) - .map((e) => e as String) - .toList(), - enumEntries: (json['enumEntries'] as List) - .map((e) => e as String) - .toList(), - sealedClasses: (json['sealedClasses'] as List) - .map((e) => e as String) - .toList(), - companionObject: json['companionObject'] as String, + functions: (json['functions'] as List?) + ?.map((e) => KotlinFunction.fromJson(e as Map)) + .toList() ?? + const [], + properties: (json['properties'] as List?) + ?.map((e) => KotlinProperty.fromJson(e as Map)) + .toList() ?? + const [], + constructors: (json['constructors'] as List?) + ?.map( + (e) => KotlinConstructor.fromJson(e as Map)) + .toList() ?? + const [], + typeParameters: (json['typeParameters'] as List?) + ?.map((e) => + KotlinTypeParameter.fromJson(e as Map)) + .toList() ?? + const [], + contextReceiverTypes: (json['contextReceiverTypes'] as List?) + ?.map((e) => KotlinType.fromJson(e as Map)) + .toList() ?? + const [], + superTypes: (json['superTypes'] as List?) + ?.map((e) => KotlinType.fromJson(e as Map)) + .toList() ?? + const [], + nestedClasses: (json['nestedClasses'] as List?) + ?.map((e) => e as String) + .toList() ?? + const [], + enumEntries: (json['enumEntries'] as List?) + ?.map((e) => e as String) + .toList() ?? + const [], + sealedClasses: (json['sealedClasses'] as List?) + ?.map((e) => e as String) + .toList() ?? + const [], + companionObject: json['companionObject'] as String?, inlineClassUnderlyingPropertyName: - json['inlineClassUnderlyingPropertyName'] as String, - inlineClassUnderlyingType: KotlinType.fromJson( - json['inlineClassUnderlyingType'] as Map), + json['inlineClassUnderlyingPropertyName'] as String?, + inlineClassUnderlyingType: json['inlineClassUnderlyingType'] == null + ? null + : KotlinType.fromJson( + json['inlineClassUnderlyingType'] as Map), flags: (json['flags'] as num).toInt(), jvmFlags: (json['jvmFlags'] as num).toInt(), ); @@ -234,6 +247,10 @@ KotlinPackage _$KotlinPackageFromJson(Map json) => ?.map((e) => KotlinFunction.fromJson(e as Map)) .toList() ?? const [], + properties: (json['properties'] as List?) + ?.map((e) => KotlinProperty.fromJson(e as Map)) + .toList() ?? + const [], ); KotlinFunction _$KotlinFunctionFromJson(Map json) => @@ -241,19 +258,26 @@ KotlinFunction _$KotlinFunctionFromJson(Map json) => name: json['name'] as String, descriptor: json['descriptor'] as String, kotlinName: json['kotlinName'] as String, - valueParameters: (json['valueParameters'] as List) - .map((e) => KotlinValueParameter.fromJson(e as Map)) - .toList(), + valueParameters: (json['valueParameters'] as List?) + ?.map((e) => + KotlinValueParameter.fromJson(e as Map)) + .toList() ?? + const [], returnType: KotlinType.fromJson(json['returnType'] as Map), - receiverParameterType: KotlinType.fromJson( - json['receiverParameterType'] as Map), - contextReceiverTypes: (json['contextReceiverTypes'] as List) - .map((e) => KotlinType.fromJson(e as Map)) - .toList(), - typeParameters: (json['typeParameters'] as List) - .map((e) => KotlinTypeParameter.fromJson(e as Map)) - .toList(), + receiverParameterType: json['receiverParameterType'] == null + ? null + : KotlinType.fromJson( + json['receiverParameterType'] as Map), + contextReceiverTypes: (json['contextReceiverTypes'] as List?) + ?.map((e) => KotlinType.fromJson(e as Map)) + .toList() ?? + const [], + typeParameters: (json['typeParameters'] as List?) + ?.map((e) => + KotlinTypeParameter.fromJson(e as Map)) + .toList() ?? + const [], flags: (json['flags'] as num).toInt(), isSuspend: json['isSuspend'] as bool, ); @@ -262,48 +286,59 @@ KotlinConstructor _$KotlinConstructorFromJson(Map json) => KotlinConstructor( name: json['name'] as String, descriptor: json['descriptor'] as String, - valueParameters: (json['valueParameters'] as List) - .map((e) => KotlinValueParameter.fromJson(e as Map)) - .toList(), + valueParameters: (json['valueParameters'] as List?) + ?.map((e) => + KotlinValueParameter.fromJson(e as Map)) + .toList() ?? + const [], flags: (json['flags'] as num).toInt(), ); KotlinProperty _$KotlinPropertyFromJson(Map json) => KotlinProperty( - fieldName: json['fieldName'] as String, - fieldDescriptor: json['fieldDescriptor'] as String, - getterName: json['getterName'] as String, - getterDescriptor: json['getterDescriptor'] as String, - setterName: json['setterName'] as String, - setterDescriptor: json['setterDescriptor'] as String, + fieldName: json['fieldName'] as String?, + fieldDescriptor: json['fieldDescriptor'] as String?, + getterName: json['getterName'] as String?, + getterDescriptor: json['getterDescriptor'] as String?, + setterName: json['setterName'] as String?, + setterDescriptor: json['setterDescriptor'] as String?, kotlinName: json['kotlinName'] as String, returnType: KotlinType.fromJson(json['returnType'] as Map), - receiverParameterType: KotlinType.fromJson( - json['receiverParameterType'] as Map), - contextReceiverTypes: (json['contextReceiverTypes'] as List) - .map((e) => KotlinType.fromJson(e as Map)) - .toList(), + receiverParameterType: json['receiverParameterType'] == null + ? null + : KotlinType.fromJson( + json['receiverParameterType'] as Map), + contextReceiverTypes: (json['contextReceiverTypes'] as List?) + ?.map((e) => KotlinType.fromJson(e as Map)) + .toList() ?? + const [], jvmFlags: (json['jvmFlags'] as num).toInt(), flags: (json['flags'] as num).toInt(), setterFlags: (json['setterFlags'] as num).toInt(), getterFlags: (json['getterFlags'] as num).toInt(), - typeParameters: (json['typeParameters'] as List) - .map((e) => KotlinTypeParameter.fromJson(e as Map)) - .toList(), - setterParameter: KotlinValueParameter.fromJson( - json['setterParameter'] as Map), + typeParameters: (json['typeParameters'] as List?) + ?.map((e) => + KotlinTypeParameter.fromJson(e as Map)) + .toList() ?? + const [], + setterParameter: json['setterParameter'] == null + ? null + : KotlinValueParameter.fromJson( + json['setterParameter'] as Map), ); KotlinType _$KotlinTypeFromJson(Map json) => KotlinType( flags: (json['flags'] as num).toInt(), kind: json['kind'] as String, - name: json['name'] as String, + name: json['name'] as String?, id: (json['id'] as num).toInt(), - arguments: (json['arguments'] as List) - .map((e) => KotlinTypeProjection.fromJson(e as Map)) - .toList(), isNullable: json['isNullable'] as bool, + arguments: (json['arguments'] as List?) + ?.map((e) => + KotlinTypeProjection.fromJson(e as Map)) + .toList() ?? + const [], ); KotlinTypeParameter _$KotlinTypeParameterFromJson(Map json) => @@ -311,9 +346,10 @@ KotlinTypeParameter _$KotlinTypeParameterFromJson(Map json) => name: json['name'] as String, id: (json['id'] as num).toInt(), flags: (json['flags'] as num).toInt(), - upperBounds: (json['upperBounds'] as List) - .map((e) => KotlinType.fromJson(e as Map)) - .toList(), + upperBounds: (json['upperBounds'] as List?) + ?.map((e) => KotlinType.fromJson(e as Map)) + .toList() ?? + const [], variance: $enumDecode(_$KmVarianceEnumMap, json['variance']), ); @@ -329,8 +365,10 @@ KotlinValueParameter _$KotlinValueParameterFromJson( name: json['name'] as String, flags: (json['flags'] as num).toInt(), type: KotlinType.fromJson(json['type'] as Map), - varargElementType: KotlinType.fromJson( - json['varargElementType'] as Map), + varargElementType: json['varargElementType'] == null + ? null + : KotlinType.fromJson( + json['varargElementType'] as Map), ); KotlinTypeProjection _$KotlinTypeProjectionFromJson( diff --git a/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart b/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart index 42b7ca029..117eacf60 100644 --- a/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart +++ b/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart @@ -117,9 +117,9 @@ class Measure<$T extends _$jni.JObject?> extends _$jni.JObject { /// from: `public T getUnit()` /// The returned object must be released after use, by calling the [release] method. - $T? getUnit() { + $T getUnit() { return _getUnit(reference.pointer, _id_getUnit as _$jni.JMethodIDPtr) - .object<$T?>(T.nullableType); + .object<$T>(T); } static final _id_convertValue = _class.instanceMethodId( @@ -140,7 +140,7 @@ class Measure<$T extends _$jni.JObject?> extends _$jni.JObject { /// from: `public final float convertValue(T measureUnit)` double convertValue( - $T? measureUnit, + $T measureUnit, ) { final _$measureUnit = measureUnit?.reference ?? _$jni.jNullReference; return _convertValue(reference.pointer, @@ -275,9 +275,9 @@ class MeasureUnit extends _$jni.JObject { /// from: `public abstract java.lang.String getSign()` /// The returned object must be released after use, by calling the [release] method. - _$jni.JString? getSign() { + _$jni.JString getSign() { return _getSign(reference.pointer, _id_getSign as _$jni.JMethodIDPtr) - .object<_$jni.JString?>(const _$jni.JStringNullableType()); + .object<_$jni.JString>(const _$jni.JStringType()); } static final _id_getCoefficient = _class.instanceMethodId( @@ -390,25 +390,25 @@ class MeasureUnit extends _$jni.JObject { abstract base mixin class $MeasureUnit { factory $MeasureUnit({ - required _$jni.JString? Function() getSign, + required _$jni.JString Function() getSign, required double Function() getCoefficient, }) = _$MeasureUnit; - _$jni.JString? getSign(); + _$jni.JString getSign(); double getCoefficient(); } final class _$MeasureUnit with $MeasureUnit { _$MeasureUnit({ - required _$jni.JString? Function() getSign, + required _$jni.JString Function() getSign, required double Function() getCoefficient, }) : _getSign = getSign, _getCoefficient = getCoefficient; - final _$jni.JString? Function() _getSign; + final _$jni.JString Function() _getSign; final double Function() _getCoefficient; - _$jni.JString? getSign() { + _$jni.JString getSign() { return _getSign(); } @@ -491,6 +491,694 @@ final class $MeasureUnit$Type extends _$jni.JObjType { } } +/// from: `com.github.dart_lang.jnigen.Nullabilty$InnerClass` +class Nullabilty_InnerClass< + $T extends _$jni.JObject?, + $U extends _$jni.JObject?, + $V extends _$jni.JObject?> extends _$jni.JObject { + @_$jni.internal + @_$core.override + final _$jni.JObjType> $type; + + @_$jni.internal + final _$jni.JObjType<$T> T; + + @_$jni.internal + final _$jni.JObjType<$U> U; + + @_$jni.internal + final _$jni.JObjType<$V> V; + + @_$jni.internal + Nullabilty_InnerClass.fromReference( + this.T, + this.U, + this.V, + _$jni.JReference reference, + ) : $type = type<$T, $U, $V>(T, U, V), + super.fromReference(reference); + + static final _class = _$jni.JClass.forName( + r'com/github/dart_lang/jnigen/Nullabilty$InnerClass'); + + /// The type which includes information such as the signature of this class. + static $Nullabilty_InnerClass$NullableType<$T, $U, $V> nullableType< + $T extends _$jni.JObject?, + $U extends _$jni.JObject?, + $V extends _$jni.JObject?>( + _$jni.JObjType<$T> T, + _$jni.JObjType<$U> U, + _$jni.JObjType<$V> V, + ) { + return $Nullabilty_InnerClass$NullableType<$T, $U, $V>( + T, + U, + V, + ); + } + + static $Nullabilty_InnerClass$Type<$T, $U, $V> type<$T extends _$jni.JObject?, + $U extends _$jni.JObject?, $V extends _$jni.JObject?>( + _$jni.JObjType<$T> T, + _$jni.JObjType<$U> U, + _$jni.JObjType<$V> V, + ) { + return $Nullabilty_InnerClass$Type<$T, $U, $V>( + T, + U, + V, + ); + } + + static final _id_new$ = _class.constructorId( + r'(Lcom/github/dart_lang/jnigen/Nullabilty;)V', + ); + + static final _new$ = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_NewObject') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public void (com.github.dart_lang.jnigen.Nullabilty $outerClass)` + /// The returned object must be released after use, by calling the [release] method. + factory Nullabilty_InnerClass( + Nullabilty<$T?, $U?> $outerClass, { + _$jni.JObjType<$T>? T, + _$jni.JObjType<$U>? U, + required _$jni.JObjType<$V> V, + }) { + T ??= _$jni.lowestCommonSuperType([ + ($outerClass.$type as $Nullabilty$Type<_$core.dynamic, _$core.dynamic>).T, + ]) as _$jni.JObjType<$T>; + U ??= _$jni.lowestCommonSuperType([ + ($outerClass.$type as $Nullabilty$Type<_$core.dynamic, _$core.dynamic>).U, + ]) as _$jni.JObjType<$U>; + final _$$outerClass = $outerClass.reference; + return Nullabilty_InnerClass<$T, $U, $V>.fromReference( + T, + U, + V, + _new$(_class.reference.pointer, _id_new$ as _$jni.JMethodIDPtr, + _$$outerClass.pointer) + .reference); + } + + static final _id_f = _class.instanceMethodId( + r'f', + r'(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V', + ); + + static final _f = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JThrowablePtr Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs< + ( + _$jni.Pointer<_$jni.Void>, + _$jni.Pointer<_$jni.Void>, + _$jni.Pointer<_$jni.Void> + )>)>>('globalEnv_CallVoidMethod') + .asFunction< + _$jni.JThrowablePtr Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.Pointer<_$jni.Void>, + _$jni.Pointer<_$jni.Void>, + _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final void f(T object, U object1, V object2)` + void f( + $T object, + $U object1, + $V object2, + ) { + final _$object = object?.reference ?? _$jni.jNullReference; + final _$object1 = object1?.reference ?? _$jni.jNullReference; + final _$object2 = object2?.reference ?? _$jni.jNullReference; + _f(reference.pointer, _id_f as _$jni.JMethodIDPtr, _$object.pointer, + _$object1.pointer, _$object2.pointer) + .check(); + } +} + +final class $Nullabilty_InnerClass$NullableType<$T extends _$jni.JObject?, + $U extends _$jni.JObject?, $V extends _$jni.JObject?> + extends _$jni.JObjType?> { + @_$jni.internal + final _$jni.JObjType<$T> T; + + @_$jni.internal + final _$jni.JObjType<$U> U; + + @_$jni.internal + final _$jni.JObjType<$V> V; + + @_$jni.internal + const $Nullabilty_InnerClass$NullableType( + this.T, + this.U, + this.V, + ); + + @_$jni.internal + @_$core.override + String get signature => + r'Lcom/github/dart_lang/jnigen/Nullabilty$InnerClass;'; + + @_$jni.internal + @_$core.override + Nullabilty_InnerClass<$T, $U, $V>? fromReference( + _$jni.JReference reference) => + reference.isNull + ? null + : Nullabilty_InnerClass<$T, $U, $V>.fromReference( + T, + U, + V, + reference, + ); + @_$jni.internal + @_$core.override + _$jni.JObjType get superType => const _$jni.JObjectNullableType(); + + @_$jni.internal + @_$core.override + _$jni.JObjType?> get nullableType => this; + + @_$jni.internal + @_$core.override + final superCount = 1; + + @_$core.override + int get hashCode => Object.hash($Nullabilty_InnerClass$NullableType, T, U, V); + + @_$core.override + bool operator ==(Object other) { + return other.runtimeType == + ($Nullabilty_InnerClass$NullableType<$T, $U, $V>) && + other is $Nullabilty_InnerClass$NullableType<$T, $U, $V> && + T == other.T && + U == other.U && + V == other.V; + } +} + +final class $Nullabilty_InnerClass$Type<$T extends _$jni.JObject?, + $U extends _$jni.JObject?, $V extends _$jni.JObject?> + extends _$jni.JObjType> { + @_$jni.internal + final _$jni.JObjType<$T> T; + + @_$jni.internal + final _$jni.JObjType<$U> U; + + @_$jni.internal + final _$jni.JObjType<$V> V; + + @_$jni.internal + const $Nullabilty_InnerClass$Type( + this.T, + this.U, + this.V, + ); + + @_$jni.internal + @_$core.override + String get signature => + r'Lcom/github/dart_lang/jnigen/Nullabilty$InnerClass;'; + + @_$jni.internal + @_$core.override + Nullabilty_InnerClass<$T, $U, $V> fromReference(_$jni.JReference reference) => + Nullabilty_InnerClass<$T, $U, $V>.fromReference( + T, + U, + V, + reference, + ); + @_$jni.internal + @_$core.override + _$jni.JObjType get superType => const _$jni.JObjectNullableType(); + + @_$jni.internal + @_$core.override + _$jni.JObjType?> get nullableType => + $Nullabilty_InnerClass$NullableType<$T, $U, $V>(T, U, V); + + @_$jni.internal + @_$core.override + final superCount = 1; + + @_$core.override + int get hashCode => Object.hash($Nullabilty_InnerClass$Type, T, U, V); + + @_$core.override + bool operator ==(Object other) { + return other.runtimeType == ($Nullabilty_InnerClass$Type<$T, $U, $V>) && + other is $Nullabilty_InnerClass$Type<$T, $U, $V> && + T == other.T && + U == other.U && + V == other.V; + } +} + +/// from: `com.github.dart_lang.jnigen.Nullabilty` +class Nullabilty<$T extends _$jni.JObject?, $U extends _$jni.JObject?> + extends _$jni.JObject { + @_$jni.internal + @_$core.override + final _$jni.JObjType> $type; + + @_$jni.internal + final _$jni.JObjType<$T> T; + + @_$jni.internal + final _$jni.JObjType<$U> U; + + @_$jni.internal + Nullabilty.fromReference( + this.T, + this.U, + _$jni.JReference reference, + ) : $type = type<$T, $U>(T, U), + super.fromReference(reference); + + static final _class = + _$jni.JClass.forName(r'com/github/dart_lang/jnigen/Nullabilty'); + + /// The type which includes information such as the signature of this class. + static $Nullabilty$NullableType<$T, $U> + nullableType<$T extends _$jni.JObject?, $U extends _$jni.JObject?>( + _$jni.JObjType<$T> T, + _$jni.JObjType<$U> U, + ) { + return $Nullabilty$NullableType<$T, $U>( + T, + U, + ); + } + + static $Nullabilty$Type<$T, $U> + type<$T extends _$jni.JObject?, $U extends _$jni.JObject?>( + _$jni.JObjType<$T> T, + _$jni.JObjType<$U> U, + ) { + return $Nullabilty$Type<$T, $U>( + T, + U, + ); + } + + static final _id_new$ = _class.constructorId( + r'(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V', + ); + + static final _new$ = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs< + ( + _$jni.Pointer<_$jni.Void>, + _$jni.Pointer<_$jni.Void>, + _$jni.Pointer<_$jni.Void> + )>)>>('globalEnv_NewObject') + .asFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.Pointer<_$jni.Void>, + _$jni.Pointer<_$jni.Void>, + _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public void (T object, U object1, U object2)` + /// The returned object must be released after use, by calling the [release] method. + factory Nullabilty( + $T object, + $U object1, + $U? object2, { + required _$jni.JObjType<$T> T, + required _$jni.JObjType<$U> U, + }) { + final _$object = object?.reference ?? _$jni.jNullReference; + final _$object1 = object1?.reference ?? _$jni.jNullReference; + final _$object2 = object2?.reference ?? _$jni.jNullReference; + return Nullabilty<$T, $U>.fromReference( + T, + U, + _new$(_class.reference.pointer, _id_new$ as _$jni.JMethodIDPtr, + _$object.pointer, _$object1.pointer, _$object2.pointer) + .reference); + } + + static final _id_getT = _class.instanceMethodId( + r'getT', + r'()Ljava/lang/Object;', + ); + + static final _getT = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + )>>('globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + )>(); + + /// from: `public final T getT()` + /// The returned object must be released after use, by calling the [release] method. + $T getT() { + return _getT(reference.pointer, _id_getT as _$jni.JMethodIDPtr) + .object<$T>(T); + } + + static final _id_getU = _class.instanceMethodId( + r'getU', + r'()Ljava/lang/Object;', + ); + + static final _getU = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + )>>('globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + )>(); + + /// from: `public final U getU()` + /// The returned object must be released after use, by calling the [release] method. + $U getU() { + return _getU(reference.pointer, _id_getU as _$jni.JMethodIDPtr) + .object<$U>(U); + } + + static final _id_getNullableU = _class.instanceMethodId( + r'getNullableU', + r'()Ljava/lang/Object;', + ); + + static final _getNullableU = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + )>>('globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + )>(); + + /// from: `public final U getNullableU()` + /// The returned object must be released after use, by calling the [release] method. + $U? getNullableU() { + return _getNullableU( + reference.pointer, _id_getNullableU as _$jni.JMethodIDPtr) + .object<$U?>(U.nullableType); + } + + static final _id_hello = _class.instanceMethodId( + r'hello', + r'()Ljava/lang/String;', + ); + + static final _hello = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + )>>('globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + )>(); + + /// from: `public final java.lang.String hello()` + /// The returned object must be released after use, by calling the [release] method. + _$jni.JString hello() { + return _hello(reference.pointer, _id_hello as _$jni.JMethodIDPtr) + .object<_$jni.JString>(const _$jni.JStringType()); + } + + static final _id_nullableHello = _class.instanceMethodId( + r'nullableHello', + r'(Z)Ljava/lang/String;', + ); + + static final _nullableHello = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Int32,)>)>>('globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, _$jni.JMethodIDPtr, int)>(); + + /// from: `public final java.lang.String nullableHello(boolean z)` + /// The returned object must be released after use, by calling the [release] method. + _$jni.JString? nullableHello( + bool z, + ) { + return _nullableHello(reference.pointer, + _id_nullableHello as _$jni.JMethodIDPtr, z ? 1 : 0) + .object<_$jni.JString?>(const _$jni.JStringNullableType()); + } + + static final _id_methodGenericEcho = _class.instanceMethodId( + r'methodGenericEcho', + r'(Ljava/lang/Object;)Ljava/lang/Object;', + ); + + static final _methodGenericEcho = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final V methodGenericEcho(V object)` + /// The returned object must be released after use, by calling the [release] method. + $V methodGenericEcho<$V extends _$jni.JObject?>( + $V object, { + required _$jni.JObjType<$V> V, + }) { + final _$object = object?.reference ?? _$jni.jNullReference; + return _methodGenericEcho(reference.pointer, + _id_methodGenericEcho as _$jni.JMethodIDPtr, _$object.pointer) + .object<$V>(V); + } + + static final _id_methodGenericNullableEcho = _class.instanceMethodId( + r'methodGenericNullableEcho', + r'(Ljava/lang/Object;)Ljava/lang/Object;', + ); + + static final _methodGenericNullableEcho = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final V methodGenericNullableEcho(V object)` + /// The returned object must be released after use, by calling the [release] method. + $V methodGenericNullableEcho<$V extends _$jni.JObject?>( + $V object, { + required _$jni.JObjType<$V> V, + }) { + final _$object = object?.reference ?? _$jni.jNullReference; + return _methodGenericNullableEcho( + reference.pointer, + _id_methodGenericNullableEcho as _$jni.JMethodIDPtr, + _$object.pointer) + .object<$V>(V); + } + + static final _id_classGenericEcho = _class.instanceMethodId( + r'classGenericEcho', + r'(Ljava/lang/Object;)Ljava/lang/Object;', + ); + + static final _classGenericEcho = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final U classGenericEcho(U object)` + /// The returned object must be released after use, by calling the [release] method. + $U classGenericEcho( + $U object, + ) { + final _$object = object?.reference ?? _$jni.jNullReference; + return _classGenericEcho(reference.pointer, + _id_classGenericEcho as _$jni.JMethodIDPtr, _$object.pointer) + .object<$U>(U); + } + + static final _id_classGenericNullableEcho = _class.instanceMethodId( + r'classGenericNullableEcho', + r'(Ljava/lang/Object;)Ljava/lang/Object;', + ); + + static final _classGenericNullableEcho = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final T classGenericNullableEcho(T object)` + /// The returned object must be released after use, by calling the [release] method. + $T classGenericNullableEcho( + $T object, + ) { + final _$object = object?.reference ?? _$jni.jNullReference; + return _classGenericNullableEcho( + reference.pointer, + _id_classGenericNullableEcho as _$jni.JMethodIDPtr, + _$object.pointer) + .object<$T>(T); + } +} + +final class $Nullabilty$NullableType<$T extends _$jni.JObject?, + $U extends _$jni.JObject?> extends _$jni.JObjType?> { + @_$jni.internal + final _$jni.JObjType<$T> T; + + @_$jni.internal + final _$jni.JObjType<$U> U; + + @_$jni.internal + const $Nullabilty$NullableType( + this.T, + this.U, + ); + + @_$jni.internal + @_$core.override + String get signature => r'Lcom/github/dart_lang/jnigen/Nullabilty;'; + + @_$jni.internal + @_$core.override + Nullabilty<$T, $U>? fromReference(_$jni.JReference reference) => + reference.isNull + ? null + : Nullabilty<$T, $U>.fromReference( + T, + U, + reference, + ); + @_$jni.internal + @_$core.override + _$jni.JObjType get superType => const _$jni.JObjectNullableType(); + + @_$jni.internal + @_$core.override + _$jni.JObjType?> get nullableType => this; + + @_$jni.internal + @_$core.override + final superCount = 1; + + @_$core.override + int get hashCode => Object.hash($Nullabilty$NullableType, T, U); + + @_$core.override + bool operator ==(Object other) { + return other.runtimeType == ($Nullabilty$NullableType<$T, $U>) && + other is $Nullabilty$NullableType<$T, $U> && + T == other.T && + U == other.U; + } +} + +final class $Nullabilty$Type<$T extends _$jni.JObject?, + $U extends _$jni.JObject?> extends _$jni.JObjType> { + @_$jni.internal + final _$jni.JObjType<$T> T; + + @_$jni.internal + final _$jni.JObjType<$U> U; + + @_$jni.internal + const $Nullabilty$Type( + this.T, + this.U, + ); + + @_$jni.internal + @_$core.override + String get signature => r'Lcom/github/dart_lang/jnigen/Nullabilty;'; + + @_$jni.internal + @_$core.override + Nullabilty<$T, $U> fromReference(_$jni.JReference reference) => + Nullabilty<$T, $U>.fromReference( + T, + U, + reference, + ); + @_$jni.internal + @_$core.override + _$jni.JObjType get superType => const _$jni.JObjectNullableType(); + + @_$jni.internal + @_$core.override + _$jni.JObjType?> get nullableType => + $Nullabilty$NullableType<$T, $U>(T, U); + + @_$jni.internal + @_$core.override + final superCount = 1; + + @_$core.override + int get hashCode => Object.hash($Nullabilty$Type, T, U); + + @_$core.override + bool operator ==(Object other) { + return other.runtimeType == ($Nullabilty$Type<$T, $U>) && + other is $Nullabilty$Type<$T, $U> && + T == other.T && + U == other.U; + } +} + /// from: `com.github.dart_lang.jnigen.Speed` class Speed extends Measure { @_$jni.internal @@ -531,9 +1219,9 @@ class Speed extends Measure { /// The returned object must be released after use, by calling the [release] method. factory Speed( double f, - SpeedUnit? speedUnit, + SpeedUnit speedUnit, ) { - final _$speedUnit = speedUnit?.reference ?? _$jni.jNullReference; + final _$speedUnit = speedUnit.reference; return Speed.fromReference(_new$(_class.reference.pointer, _id_new$ as _$jni.JMethodIDPtr, f, _$speedUnit.pointer) .reference); @@ -581,9 +1269,9 @@ class Speed extends Measure { /// from: `public com.github.dart_lang.jnigen.SpeedUnit getUnit()` /// The returned object must be released after use, by calling the [release] method. - SpeedUnit? getUnit$1() { + SpeedUnit getUnit$1() { return _getUnit$1(reference.pointer, _id_getUnit$1 as _$jni.JMethodIDPtr) - .object(const $SpeedUnit$NullableType()); + .object(const $SpeedUnit$Type()); } static final _id_toString$1 = _class.instanceMethodId( @@ -605,9 +1293,9 @@ class Speed extends Measure { /// from: `public java.lang.String toString()` /// The returned object must be released after use, by calling the [release] method. - _$jni.JString? toString$1() { + _$jni.JString toString$1() { return _toString$1(reference.pointer, _id_toString$1 as _$jni.JMethodIDPtr) - .object<_$jni.JString?>(const _$jni.JStringNullableType()); + .object<_$jni.JString>(const _$jni.JStringType()); } static final _id_component1 = _class.instanceMethodId( @@ -652,9 +1340,9 @@ class Speed extends Measure { /// from: `public final com.github.dart_lang.jnigen.SpeedUnit component2()` /// The returned object must be released after use, by calling the [release] method. - SpeedUnit? component2() { + SpeedUnit component2() { return _component2(reference.pointer, _id_component2 as _$jni.JMethodIDPtr) - .object(const $SpeedUnit$NullableType()); + .object(const $SpeedUnit$Type()); } static final _id_copy = _class.instanceMethodId( @@ -678,14 +1366,14 @@ class Speed extends Measure { /// from: `public final com.github.dart_lang.jnigen.Speed copy(float f, com.github.dart_lang.jnigen.SpeedUnit speedUnit)` /// The returned object must be released after use, by calling the [release] method. - Speed? copy( + Speed copy( double f, - SpeedUnit? speedUnit, + SpeedUnit speedUnit, ) { - final _$speedUnit = speedUnit?.reference ?? _$jni.jNullReference; + final _$speedUnit = speedUnit.reference; return _copy(reference.pointer, _id_copy as _$jni.JMethodIDPtr, f, _$speedUnit.pointer) - .object(const $Speed$NullableType()); + .object(const $Speed$Type()); } static final _id_hashCode$1 = _class.instanceMethodId( @@ -868,9 +1556,9 @@ class SpeedUnit extends _$jni.JObject { /// from: `public java.lang.String getSign()` /// The returned object must be released after use, by calling the [release] method. - _$jni.JString? getSign() { + _$jni.JString getSign() { return _getSign(reference.pointer, _id_getSign as _$jni.JMethodIDPtr) - .object<_$jni.JString?>(const _$jni.JStringNullableType()); + .object<_$jni.JString>(const _$jni.JStringType()); } static final _id_getCoefficient = _class.instanceMethodId( @@ -1090,7 +1778,7 @@ class SuspendFun extends _$jni.JObject { _sayHello(reference.pointer, _id_sayHello as _$jni.JMethodIDPtr, _$continuation.pointer) - .object<_$jni.JObject?>(const _$jni.JObjectNullableType()); + .object<_$jni.JObject>(const _$jni.JObjectType()); _$continuation.release(); final $o = _$jni.JGlobalReference(_$jni.JObjectPtr.fromAddress(await $p.first)); @@ -1135,7 +1823,7 @@ class SuspendFun extends _$jni.JObject { final _$string = string?.reference ?? _$jni.jNullReference; _sayHello$1(reference.pointer, _id_sayHello$1 as _$jni.JMethodIDPtr, _$string.pointer, _$continuation.pointer) - .object<_$jni.JObject?>(const _$jni.JObjectNullableType()); + .object<_$jni.JObject>(const _$jni.JObjectType()); _$continuation.release(); final $o = _$jni.JGlobalReference(_$jni.JObjectPtr.fromAddress(await $p.first)); diff --git a/pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullabilty.kt b/pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullabilty.kt new file mode 100644 index 000000000..cf72c9809 --- /dev/null +++ b/pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullabilty.kt @@ -0,0 +1,31 @@ +package com.github.dart_lang.jnigen + +class Nullabilty(val t: T, val u: U, val nullableU: U?) { + fun hello(): String { + return "hello" + } + + fun nullableHello(returnNull: Boolean): String? { + return if (returnNull) null else "hello" + } + + fun methodGenericEcho(v: V): V { + return v + } + + fun methodGenericNullableEcho(v: V): V { + return v + } + + fun classGenericEcho(u: U): U { + return u + } + + fun classGenericNullableEcho(t: T): T { + return t + } + + inner class InnerClass { + fun f(t: T, u: U, v: V) {} + } +} \ No newline at end of file diff --git a/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart b/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart index 1dca0b082..bfe4f2385 100644 --- a/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart +++ b/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart @@ -32,7 +32,7 @@ void registerTests(String groupName, TestRunnerCallback test) { test('Generics', () { using((arena) { - final speed = Speed(10, SpeedUnit.MetrePerSec)..releasedBy(arena); + final speed = Speed(10, SpeedUnit.MetrePerSec!)..releasedBy(arena); expect(speed.convertValue(SpeedUnit.KmPerHour), closeTo(36, 1e-6)); }); }); From d05f2f0ecea27aab0f1ab86953b5f9c15636546c Mon Sep 17 00:00:00 2001 From: Hossein Yousefi Date: Thu, 28 Nov 2024 16:35:41 +0100 Subject: [PATCH 03/13] Add tests --- .../test/kotlin_test/bindings/kotlin.dart | 26 ++++++ .../com/github/dart_lang/jnigen/Nullabilty.kt | 2 +- .../kotlin_test/runtime_test_registrant.dart | 81 +++++++++++++++++++ 3 files changed, 108 insertions(+), 1 deletion(-) diff --git a/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart b/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart index 117eacf60..aa48a4b54 100644 --- a/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart +++ b/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart @@ -912,6 +912,32 @@ class Nullabilty<$T extends _$jni.JObject?, $U extends _$jni.JObject?> .object<$U?>(U.nullableType); } + static final _id_setNullableU = _class.instanceMethodId( + r'setNullableU', + r'(Ljava/lang/Object;)V', + ); + + static final _setNullableU = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JThrowablePtr Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallVoidMethod') + .asFunction< + _$jni.JThrowablePtr Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final void setNullableU(U object)` + void setNullableU( + $U? object, + ) { + final _$object = object?.reference ?? _$jni.jNullReference; + _setNullableU(reference.pointer, _id_setNullableU as _$jni.JMethodIDPtr, + _$object.pointer) + .check(); + } + static final _id_hello = _class.instanceMethodId( r'hello', r'()Ljava/lang/String;', diff --git a/pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullabilty.kt b/pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullabilty.kt index cf72c9809..dded93259 100644 --- a/pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullabilty.kt +++ b/pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullabilty.kt @@ -1,6 +1,6 @@ package com.github.dart_lang.jnigen -class Nullabilty(val t: T, val u: U, val nullableU: U?) { +class Nullabilty(val t: T, val u: U, var nullableU: U?) { fun hello(): String { return "hello" } diff --git a/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart b/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart index bfe4f2385..a1368e947 100644 --- a/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart +++ b/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart @@ -36,5 +36,86 @@ void registerTests(String groupName, TestRunnerCallback test) { expect(speed.convertValue(SpeedUnit.KmPerHour), closeTo(36, 1e-6)); }); }); + + group('Nullability', () { + Nullabilty testObject(Arena arena) { + return Nullabilty( + null, + 'hello'.toJString(), + null, + T: JString.nullableType, + U: JString.type, + )..releasedBy(arena); + } + + test('Getters', () { + using((arena) { + final obj = testObject(arena); + expect( + obj.getU().toDartString(releaseOriginal: true), + 'hello', + ); + expect(obj.getT(), null); + expect(obj.getNullableU(), null); + }); + }); + test('Setters', () { + using((arena) { + final obj = testObject(arena); + obj.setNullableU('hello'.toJString()..releasedBy(arena)); + expect( + obj.getNullableU()!.toDartString(releaseOriginal: true), + 'hello', + ); + }); + }); + test('Methods', () { + using((arena) { + final obj = testObject(arena); + expect(obj.hello().toDartString(releaseOriginal: true), 'hello'); + expect( + obj.nullableHello(false)!.toDartString(releaseOriginal: true), + 'hello', + ); + expect(obj.nullableHello(true), null); + expect( + obj + .classGenericEcho('hello'.toJString()..releasedBy(arena)) + .toDartString(releaseOriginal: true), + 'hello', + ); + expect( + obj + .classGenericNullableEcho( + 'hello'.toJString()..releasedBy(arena))! + .toDartString(releaseOriginal: true), + 'hello', + ); + expect(obj.classGenericNullableEcho(null), null); + expect( + obj + .methodGenericEcho( + 'hello'.toJString()..releasedBy(arena), + V: JString.type, + ) + .toDartString(releaseOriginal: true), + 'hello', + ); + expect( + obj + .methodGenericNullableEcho( + 'hello'.toJString()..releasedBy(arena), + V: JString.nullableType, + )! + .toDartString(releaseOriginal: true), + 'hello', + ); + expect( + obj.methodGenericNullableEcho(null, V: JString.nullableType), + null, + ); + }); + }); + }); }); } From e87752035a5e59a69543dc10797c3b65fbd650cb Mon Sep 17 00:00:00 2001 From: Hossein Yousefi Date: Thu, 28 Nov 2024 19:15:10 +0100 Subject: [PATCH 04/13] Add more tests --- pkgs/jnigen/CHANGELOG.md | 2 +- .../lib/src/bindings/kotlin_processor.dart | 34 +- .../test/kotlin_test/bindings/kotlin.dart | 1599 ++++++++++++++++- .../github/dart_lang/jnigen/Nullability.kt | 79 + .../com/github/dart_lang/jnigen/Nullabilty.kt | 31 - .../kotlin_test/runtime_test_registrant.dart | 117 +- 6 files changed, 1738 insertions(+), 124 deletions(-) create mode 100644 pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullability.kt delete mode 100644 pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullabilty.kt diff --git a/pkgs/jnigen/CHANGELOG.md b/pkgs/jnigen/CHANGELOG.md index 7d94206cb..f8408ec7c 100644 --- a/pkgs/jnigen/CHANGELOG.md +++ b/pkgs/jnigen/CHANGELOG.md @@ -1,7 +1,7 @@ ## 0.13.0-wip - **Breaking Change**([#1644](https://github.com/dart-lang/native/issues/1644)): - Generate null-safe Dart bindings. + Generate null-safe Dart bindings for Java and Kotlin. ## 0.12.2 diff --git a/pkgs/jnigen/lib/src/bindings/kotlin_processor.dart b/pkgs/jnigen/lib/src/bindings/kotlin_processor.dart index f8cd47798..6c46ab63c 100644 --- a/pkgs/jnigen/lib/src/bindings/kotlin_processor.dart +++ b/pkgs/jnigen/lib/src/bindings/kotlin_processor.dart @@ -5,6 +5,30 @@ import '../elements/elements.dart'; import 'visitor.dart'; +String _toJavaBinaryName(String kotlinBinaryName) { + final binaryName = kotlinBinaryName.replaceAll('/', '.'); + return const { + 'kotlin.Any': 'java.lang.Object', + 'kotlin.Byte': 'java.lang.Byte', + 'kotlin.Short': 'java.lang.Short', + 'kotlin.Int': 'java.lang.Integer', + 'kotlin.Long': 'java.lang.Long', + 'kotlin.Char': 'java.lang.Character', + 'kotlin.Float': 'java.lang.Float', + 'kotlin.Double': 'java.lang.Double', + 'kotlin.Boolean': 'java.lang.Boolean', + 'kotlin.Cloneable': 'java.lang.Cloneable', + 'kotlin.Comparable': 'java.lang.Comparable', + 'kotlin.Enum': 'java.lang.Enum', + 'kotlin.Annotation': 'java.lang.annotation.Annotation', + 'kotlin.CharSequence': 'java.lang.CharSequence', + 'kotlin.String': 'java.lang.String', + 'kotlin.Number': 'java.lang.Number', + 'kotlin.Throwable': 'java.lang.Throwable', + }[binaryName] ?? + binaryName; +} + /// A [Visitor] that adds the the information from Kotlin's metadata to the Java /// classes and methods. class KotlinProcessor extends Visitor { @@ -29,6 +53,10 @@ class _KotlinClassProcessor extends Visitor { node.typeParams[i].accept( _KotlinTypeParamProcessor(node.kotlinClass!.typeParameters[i])); } + node.superclass?.accept(_KotlinTypeProcessor( + node.kotlinClass!.superTypes.firstWhere((superType) => + _toJavaBinaryName(superType.name ?? '') == node.superclass!.name), + )); } // Matching fields and properties from the metadata. @@ -103,6 +131,10 @@ class _KotlinMethodProcessor extends Visitor { void visit(Method node) { node.returnType.accept(_KotlinTypeProcessor(function.returnType)); _processParams(node.params, function.valueParameters); + for (var i = 0; i < node.typeParams.length; ++i) { + node.typeParams[i] + .accept(_KotlinTypeParamProcessor(function.typeParameters[i])); + } if (function.isSuspend) { const kotlinContinutationType = 'kotlin.coroutines.Continuation'; assert(node.params.isNotEmpty && @@ -191,7 +223,7 @@ class _KotlinTypeParamProcessor extends Visitor { final bounds = {}; for (final bound in kotlinBounds) { if (bound.name case final boundName?) { - bounds[boundName] = bound; + bounds[_toJavaBinaryName(boundName)] = bound; } } for (final bound in node.bounds) { diff --git a/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart b/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart index aa48a4b54..a61bd3ce0 100644 --- a/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart +++ b/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart @@ -33,14 +33,14 @@ // ignore_for_file: unused_shown_name // ignore_for_file: use_super_parameters -import 'dart:core' show Object, String, bool, double, int; import 'dart:core' as _$core; +import 'dart:core' show Object, String, bool, double, int; import 'package:jni/_internal.dart' as _$jni; import 'package:jni/jni.dart' as _$jni; /// from: `com.github.dart_lang.jnigen.Measure` -class Measure<$T extends _$jni.JObject?> extends _$jni.JObject { +class Measure<$T extends _$jni.JObject> extends _$jni.JObject { @_$jni.internal @_$core.override final _$jni.JObjType> $type; @@ -59,7 +59,7 @@ class Measure<$T extends _$jni.JObject?> extends _$jni.JObject { _$jni.JClass.forName(r'com/github/dart_lang/jnigen/Measure'); /// The type which includes information such as the signature of this class. - static $Measure$NullableType<$T> nullableType<$T extends _$jni.JObject?>( + static $Measure$NullableType<$T> nullableType<$T extends _$jni.JObject>( _$jni.JObjType<$T> T, ) { return $Measure$NullableType<$T>( @@ -67,7 +67,7 @@ class Measure<$T extends _$jni.JObject?> extends _$jni.JObject { ); } - static $Measure$Type<$T> type<$T extends _$jni.JObject?>( + static $Measure$Type<$T> type<$T extends _$jni.JObject>( _$jni.JObjType<$T> T, ) { return $Measure$Type<$T>( @@ -142,14 +142,14 @@ class Measure<$T extends _$jni.JObject?> extends _$jni.JObject { double convertValue( $T measureUnit, ) { - final _$measureUnit = measureUnit?.reference ?? _$jni.jNullReference; + final _$measureUnit = measureUnit.reference; return _convertValue(reference.pointer, _id_convertValue as _$jni.JMethodIDPtr, _$measureUnit.pointer) .float; } } -final class $Measure$NullableType<$T extends _$jni.JObject?> +final class $Measure$NullableType<$T extends _$jni.JObject> extends _$jni.JObjType?> { @_$jni.internal final _$jni.JObjType<$T> T; @@ -173,7 +173,7 @@ final class $Measure$NullableType<$T extends _$jni.JObject?> ); @_$jni.internal @_$core.override - _$jni.JObjType get superType => const _$jni.JObjectNullableType(); + _$jni.JObjType get superType => const _$jni.JObjectType(); @_$jni.internal @_$core.override @@ -194,7 +194,7 @@ final class $Measure$NullableType<$T extends _$jni.JObject?> } } -final class $Measure$Type<$T extends _$jni.JObject?> +final class $Measure$Type<$T extends _$jni.JObject> extends _$jni.JObjType> { @_$jni.internal final _$jni.JObjType<$T> T; @@ -217,7 +217,7 @@ final class $Measure$Type<$T extends _$jni.JObject?> ); @_$jni.internal @_$core.override - _$jni.JObjType get superType => const _$jni.JObjectNullableType(); + _$jni.JObjType get superType => const _$jni.JObjectType(); @_$jni.internal @_$core.override @@ -434,7 +434,7 @@ final class $MeasureUnit$NullableType extends _$jni.JObjType { ); @_$jni.internal @_$core.override - _$jni.JObjType get superType => const _$jni.JObjectNullableType(); + _$jni.JObjType get superType => const _$jni.JObjectType(); @_$jni.internal @_$core.override @@ -470,7 +470,7 @@ final class $MeasureUnit$Type extends _$jni.JObjType { ); @_$jni.internal @_$core.override - _$jni.JObjType get superType => const _$jni.JObjectNullableType(); + _$jni.JObjType get superType => const _$jni.JObjectType(); @_$jni.internal @_$core.override @@ -491,14 +491,12 @@ final class $MeasureUnit$Type extends _$jni.JObjType { } } -/// from: `com.github.dart_lang.jnigen.Nullabilty$InnerClass` -class Nullabilty_InnerClass< - $T extends _$jni.JObject?, - $U extends _$jni.JObject?, - $V extends _$jni.JObject?> extends _$jni.JObject { +/// from: `com.github.dart_lang.jnigen.Nullability$InnerClass` +class Nullability_InnerClass<$T extends _$jni.JObject?, + $U extends _$jni.JObject, $V extends _$jni.JObject?> extends _$jni.JObject { @_$jni.internal @_$core.override - final _$jni.JObjType> $type; + final _$jni.JObjType> $type; @_$jni.internal final _$jni.JObjType<$T> T; @@ -510,7 +508,7 @@ class Nullabilty_InnerClass< final _$jni.JObjType<$V> V; @_$jni.internal - Nullabilty_InnerClass.fromReference( + Nullability_InnerClass.fromReference( this.T, this.U, this.V, @@ -519,31 +517,33 @@ class Nullabilty_InnerClass< super.fromReference(reference); static final _class = _$jni.JClass.forName( - r'com/github/dart_lang/jnigen/Nullabilty$InnerClass'); + r'com/github/dart_lang/jnigen/Nullability$InnerClass'); /// The type which includes information such as the signature of this class. - static $Nullabilty_InnerClass$NullableType<$T, $U, $V> nullableType< + static $Nullability_InnerClass$NullableType<$T, $U, $V> nullableType< $T extends _$jni.JObject?, - $U extends _$jni.JObject?, + $U extends _$jni.JObject, $V extends _$jni.JObject?>( _$jni.JObjType<$T> T, _$jni.JObjType<$U> U, _$jni.JObjType<$V> V, ) { - return $Nullabilty_InnerClass$NullableType<$T, $U, $V>( + return $Nullability_InnerClass$NullableType<$T, $U, $V>( T, U, V, ); } - static $Nullabilty_InnerClass$Type<$T, $U, $V> type<$T extends _$jni.JObject?, - $U extends _$jni.JObject?, $V extends _$jni.JObject?>( + static $Nullability_InnerClass$Type<$T, $U, $V> type< + $T extends _$jni.JObject?, + $U extends _$jni.JObject, + $V extends _$jni.JObject?>( _$jni.JObjType<$T> T, _$jni.JObjType<$U> U, _$jni.JObjType<$V> V, ) { - return $Nullabilty_InnerClass$Type<$T, $U, $V>( + return $Nullability_InnerClass$Type<$T, $U, $V>( T, U, V, @@ -551,7 +551,7 @@ class Nullabilty_InnerClass< } static final _id_new$ = _class.constructorId( - r'(Lcom/github/dart_lang/jnigen/Nullabilty;)V', + r'(Lcom/github/dart_lang/jnigen/Nullability;)V', ); static final _new$ = _$jni.ProtectedJniExtensions.lookup< @@ -565,22 +565,24 @@ class Nullabilty_InnerClass< _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); - /// from: `public void (com.github.dart_lang.jnigen.Nullabilty $outerClass)` + /// from: `public void (com.github.dart_lang.jnigen.Nullability $outerClass)` /// The returned object must be released after use, by calling the [release] method. - factory Nullabilty_InnerClass( - Nullabilty<$T?, $U?> $outerClass, { + factory Nullability_InnerClass( + Nullability<$T?, $U> $outerClass, { _$jni.JObjType<$T>? T, _$jni.JObjType<$U>? U, required _$jni.JObjType<$V> V, }) { T ??= _$jni.lowestCommonSuperType([ - ($outerClass.$type as $Nullabilty$Type<_$core.dynamic, _$core.dynamic>).T, + ($outerClass.$type as $Nullability$Type<_$core.dynamic, _$core.dynamic>) + .T, ]) as _$jni.JObjType<$T>; U ??= _$jni.lowestCommonSuperType([ - ($outerClass.$type as $Nullabilty$Type<_$core.dynamic, _$core.dynamic>).U, + ($outerClass.$type as $Nullability$Type<_$core.dynamic, _$core.dynamic>) + .U, ]) as _$jni.JObjType<$U>; final _$$outerClass = $outerClass.reference; - return Nullabilty_InnerClass<$T, $U, $V>.fromReference( + return Nullability_InnerClass<$T, $U, $V>.fromReference( T, U, V, @@ -620,7 +622,7 @@ class Nullabilty_InnerClass< $V object2, ) { final _$object = object?.reference ?? _$jni.jNullReference; - final _$object1 = object1?.reference ?? _$jni.jNullReference; + final _$object1 = object1.reference; final _$object2 = object2?.reference ?? _$jni.jNullReference; _f(reference.pointer, _id_f as _$jni.JMethodIDPtr, _$object.pointer, _$object1.pointer, _$object2.pointer) @@ -628,9 +630,9 @@ class Nullabilty_InnerClass< } } -final class $Nullabilty_InnerClass$NullableType<$T extends _$jni.JObject?, - $U extends _$jni.JObject?, $V extends _$jni.JObject?> - extends _$jni.JObjType?> { +final class $Nullability_InnerClass$NullableType<$T extends _$jni.JObject?, + $U extends _$jni.JObject, $V extends _$jni.JObject?> + extends _$jni.JObjType?> { @_$jni.internal final _$jni.JObjType<$T> T; @@ -641,7 +643,7 @@ final class $Nullabilty_InnerClass$NullableType<$T extends _$jni.JObject?, final _$jni.JObjType<$V> V; @_$jni.internal - const $Nullabilty_InnerClass$NullableType( + const $Nullability_InnerClass$NullableType( this.T, this.U, this.V, @@ -650,15 +652,15 @@ final class $Nullabilty_InnerClass$NullableType<$T extends _$jni.JObject?, @_$jni.internal @_$core.override String get signature => - r'Lcom/github/dart_lang/jnigen/Nullabilty$InnerClass;'; + r'Lcom/github/dart_lang/jnigen/Nullability$InnerClass;'; @_$jni.internal @_$core.override - Nullabilty_InnerClass<$T, $U, $V>? fromReference( + Nullability_InnerClass<$T, $U, $V>? fromReference( _$jni.JReference reference) => reference.isNull ? null - : Nullabilty_InnerClass<$T, $U, $V>.fromReference( + : Nullability_InnerClass<$T, $U, $V>.fromReference( T, U, V, @@ -666,33 +668,34 @@ final class $Nullabilty_InnerClass$NullableType<$T extends _$jni.JObject?, ); @_$jni.internal @_$core.override - _$jni.JObjType get superType => const _$jni.JObjectNullableType(); + _$jni.JObjType get superType => const _$jni.JObjectType(); @_$jni.internal @_$core.override - _$jni.JObjType?> get nullableType => this; + _$jni.JObjType?> get nullableType => this; @_$jni.internal @_$core.override final superCount = 1; @_$core.override - int get hashCode => Object.hash($Nullabilty_InnerClass$NullableType, T, U, V); + int get hashCode => + Object.hash($Nullability_InnerClass$NullableType, T, U, V); @_$core.override bool operator ==(Object other) { return other.runtimeType == - ($Nullabilty_InnerClass$NullableType<$T, $U, $V>) && - other is $Nullabilty_InnerClass$NullableType<$T, $U, $V> && + ($Nullability_InnerClass$NullableType<$T, $U, $V>) && + other is $Nullability_InnerClass$NullableType<$T, $U, $V> && T == other.T && U == other.U && V == other.V; } } -final class $Nullabilty_InnerClass$Type<$T extends _$jni.JObject?, - $U extends _$jni.JObject?, $V extends _$jni.JObject?> - extends _$jni.JObjType> { +final class $Nullability_InnerClass$Type<$T extends _$jni.JObject?, + $U extends _$jni.JObject, $V extends _$jni.JObject?> + extends _$jni.JObjType> { @_$jni.internal final _$jni.JObjType<$T> T; @@ -703,7 +706,7 @@ final class $Nullabilty_InnerClass$Type<$T extends _$jni.JObject?, final _$jni.JObjType<$V> V; @_$jni.internal - const $Nullabilty_InnerClass$Type( + const $Nullability_InnerClass$Type( this.T, this.U, this.V, @@ -712,12 +715,13 @@ final class $Nullabilty_InnerClass$Type<$T extends _$jni.JObject?, @_$jni.internal @_$core.override String get signature => - r'Lcom/github/dart_lang/jnigen/Nullabilty$InnerClass;'; + r'Lcom/github/dart_lang/jnigen/Nullability$InnerClass;'; @_$jni.internal @_$core.override - Nullabilty_InnerClass<$T, $U, $V> fromReference(_$jni.JReference reference) => - Nullabilty_InnerClass<$T, $U, $V>.fromReference( + Nullability_InnerClass<$T, $U, $V> fromReference( + _$jni.JReference reference) => + Nullability_InnerClass<$T, $U, $V>.fromReference( T, U, V, @@ -725,36 +729,36 @@ final class $Nullabilty_InnerClass$Type<$T extends _$jni.JObject?, ); @_$jni.internal @_$core.override - _$jni.JObjType get superType => const _$jni.JObjectNullableType(); + _$jni.JObjType get superType => const _$jni.JObjectType(); @_$jni.internal @_$core.override - _$jni.JObjType?> get nullableType => - $Nullabilty_InnerClass$NullableType<$T, $U, $V>(T, U, V); + _$jni.JObjType?> get nullableType => + $Nullability_InnerClass$NullableType<$T, $U, $V>(T, U, V); @_$jni.internal @_$core.override final superCount = 1; @_$core.override - int get hashCode => Object.hash($Nullabilty_InnerClass$Type, T, U, V); + int get hashCode => Object.hash($Nullability_InnerClass$Type, T, U, V); @_$core.override bool operator ==(Object other) { - return other.runtimeType == ($Nullabilty_InnerClass$Type<$T, $U, $V>) && - other is $Nullabilty_InnerClass$Type<$T, $U, $V> && + return other.runtimeType == ($Nullability_InnerClass$Type<$T, $U, $V>) && + other is $Nullability_InnerClass$Type<$T, $U, $V> && T == other.T && U == other.U && V == other.V; } } -/// from: `com.github.dart_lang.jnigen.Nullabilty` -class Nullabilty<$T extends _$jni.JObject?, $U extends _$jni.JObject?> +/// from: `com.github.dart_lang.jnigen.Nullability` +class Nullability<$T extends _$jni.JObject?, $U extends _$jni.JObject> extends _$jni.JObject { @_$jni.internal @_$core.override - final _$jni.JObjType> $type; + final _$jni.JObjType> $type; @_$jni.internal final _$jni.JObjType<$T> T; @@ -763,7 +767,7 @@ class Nullabilty<$T extends _$jni.JObject?, $U extends _$jni.JObject?> final _$jni.JObjType<$U> U; @_$jni.internal - Nullabilty.fromReference( + Nullability.fromReference( this.T, this.U, _$jni.JReference reference, @@ -771,26 +775,26 @@ class Nullabilty<$T extends _$jni.JObject?, $U extends _$jni.JObject?> super.fromReference(reference); static final _class = - _$jni.JClass.forName(r'com/github/dart_lang/jnigen/Nullabilty'); + _$jni.JClass.forName(r'com/github/dart_lang/jnigen/Nullability'); /// The type which includes information such as the signature of this class. - static $Nullabilty$NullableType<$T, $U> - nullableType<$T extends _$jni.JObject?, $U extends _$jni.JObject?>( + static $Nullability$NullableType<$T, $U> + nullableType<$T extends _$jni.JObject?, $U extends _$jni.JObject>( _$jni.JObjType<$T> T, _$jni.JObjType<$U> U, ) { - return $Nullabilty$NullableType<$T, $U>( + return $Nullability$NullableType<$T, $U>( T, U, ); } - static $Nullabilty$Type<$T, $U> - type<$T extends _$jni.JObject?, $U extends _$jni.JObject?>( + static $Nullability$Type<$T, $U> + type<$T extends _$jni.JObject?, $U extends _$jni.JObject>( _$jni.JObjType<$T> T, _$jni.JObjType<$U> U, ) { - return $Nullabilty$Type<$T, $U>( + return $Nullability$Type<$T, $U>( T, U, ); @@ -821,17 +825,20 @@ class Nullabilty<$T extends _$jni.JObject?, $U extends _$jni.JObject?> /// from: `public void (T object, U object1, U object2)` /// The returned object must be released after use, by calling the [release] method. - factory Nullabilty( + factory Nullability( $T object, $U object1, $U? object2, { required _$jni.JObjType<$T> T, - required _$jni.JObjType<$U> U, + _$jni.JObjType<$U>? U, }) { + U ??= _$jni.lowestCommonSuperType([ + object1.$type, + ]) as _$jni.JObjType<$U>; final _$object = object?.reference ?? _$jni.jNullReference; - final _$object1 = object1?.reference ?? _$jni.jNullReference; + final _$object1 = object1.reference; final _$object2 = object2?.reference ?? _$jni.jNullReference; - return Nullabilty<$T, $U>.fromReference( + return Nullability<$T, $U>.fromReference( T, U, _new$(_class.reference.pointer, _id_new$ as _$jni.JMethodIDPtr, @@ -930,7 +937,7 @@ class Nullabilty<$T extends _$jni.JObject?, $U extends _$jni.JObject?> /// from: `public final void setNullableU(U object)` void setNullableU( - $U? object, + $U object, ) { final _$object = object?.reference ?? _$jni.jNullReference; _setNullableU(reference.pointer, _id_setNullableU as _$jni.JMethodIDPtr, @@ -1005,11 +1012,14 @@ class Nullabilty<$T extends _$jni.JObject?, $U extends _$jni.JObject?> /// from: `public final V methodGenericEcho(V object)` /// The returned object must be released after use, by calling the [release] method. - $V methodGenericEcho<$V extends _$jni.JObject?>( + $V methodGenericEcho<$V extends _$jni.JObject>( $V object, { - required _$jni.JObjType<$V> V, + _$jni.JObjType<$V>? V, }) { - final _$object = object?.reference ?? _$jni.jNullReference; + V ??= _$jni.lowestCommonSuperType([ + object.$type, + ]) as _$jni.JObjType<$V>; + final _$object = object.reference; return _methodGenericEcho(reference.pointer, _id_methodGenericEcho as _$jni.JMethodIDPtr, _$object.pointer) .object<$V>(V); @@ -1066,7 +1076,7 @@ class Nullabilty<$T extends _$jni.JObject?, $U extends _$jni.JObject?> $U classGenericEcho( $U object, ) { - final _$object = object?.reference ?? _$jni.jNullReference; + final _$object = object.reference; return _classGenericEcho(reference.pointer, _id_classGenericEcho as _$jni.JMethodIDPtr, _$object.pointer) .object<$U>(U); @@ -1100,6 +1110,1419 @@ class Nullabilty<$T extends _$jni.JObject?, $U extends _$jni.JObject?> _$object.pointer) .object<$T>(T); } + + static final _id_firstOf = _class.instanceMethodId( + r'firstOf', + r'(Ljava/util/List;)Ljava/lang/String;', + ); + + static final _firstOf = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final java.lang.String firstOf(java.util.List list)` + /// The returned object must be released after use, by calling the [release] method. + _$jni.JString firstOf( + _$jni.JList<_$jni.JString> list, + ) { + final _$list = list.reference; + return _firstOf(reference.pointer, _id_firstOf as _$jni.JMethodIDPtr, + _$list.pointer) + .object<_$jni.JString>(const _$jni.JStringType()); + } + + static final _id_firstOfNullable = _class.instanceMethodId( + r'firstOfNullable', + r'(Ljava/util/List;)Ljava/lang/String;', + ); + + static final _firstOfNullable = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final java.lang.String firstOfNullable(java.util.List list)` + /// The returned object must be released after use, by calling the [release] method. + _$jni.JString? firstOfNullable( + _$jni.JList<_$jni.JString?> list, + ) { + final _$list = list.reference; + return _firstOfNullable(reference.pointer, + _id_firstOfNullable as _$jni.JMethodIDPtr, _$list.pointer) + .object<_$jni.JString?>(const _$jni.JStringNullableType()); + } + + static final _id_classGenericFirstOf = _class.instanceMethodId( + r'classGenericFirstOf', + r'(Ljava/util/List;)Ljava/lang/Object;', + ); + + static final _classGenericFirstOf = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final U classGenericFirstOf(java.util.List list)` + /// The returned object must be released after use, by calling the [release] method. + $U classGenericFirstOf( + _$jni.JList<$U> list, + ) { + final _$list = list.reference; + return _classGenericFirstOf(reference.pointer, + _id_classGenericFirstOf as _$jni.JMethodIDPtr, _$list.pointer) + .object<$U>(U); + } + + static final _id_classGenericFirstOfNullable = _class.instanceMethodId( + r'classGenericFirstOfNullable', + r'(Ljava/util/List;)Ljava/lang/Object;', + ); + + static final _classGenericFirstOfNullable = + _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final T classGenericFirstOfNullable(java.util.List list)` + /// The returned object must be released after use, by calling the [release] method. + $T classGenericFirstOfNullable( + _$jni.JList<$T> list, + ) { + final _$list = list.reference; + return _classGenericFirstOfNullable( + reference.pointer, + _id_classGenericFirstOfNullable as _$jni.JMethodIDPtr, + _$list.pointer) + .object<$T>(T); + } + + static final _id_methodGenericFirstOf = _class.instanceMethodId( + r'methodGenericFirstOf', + r'(Ljava/util/List;)Ljava/lang/Object;', + ); + + static final _methodGenericFirstOf = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final V methodGenericFirstOf(java.util.List list)` + /// The returned object must be released after use, by calling the [release] method. + $V methodGenericFirstOf<$V extends _$jni.JObject>( + _$jni.JList<$V> list, { + _$jni.JObjType<$V>? V, + }) { + V ??= _$jni.lowestCommonSuperType([ + (list.$type as _$jni.JListType<_$core.dynamic>).E, + ]) as _$jni.JObjType<$V>; + final _$list = list.reference; + return _methodGenericFirstOf(reference.pointer, + _id_methodGenericFirstOf as _$jni.JMethodIDPtr, _$list.pointer) + .object<$V>(V); + } + + static final _id_methodGenericFirstOfNullable = _class.instanceMethodId( + r'methodGenericFirstOfNullable', + r'(Ljava/util/List;)Ljava/lang/Object;', + ); + + static final _methodGenericFirstOfNullable = + _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final V methodGenericFirstOfNullable(java.util.List list)` + /// The returned object must be released after use, by calling the [release] method. + $V methodGenericFirstOfNullable<$V extends _$jni.JObject?>( + _$jni.JList<$V> list, { + _$jni.JObjType<$V>? V, + }) { + V ??= _$jni.lowestCommonSuperType([ + (list.$type as _$jni.JListType<_$core.dynamic>).E, + ]) as _$jni.JObjType<$V>; + final _$list = list.reference; + return _methodGenericFirstOfNullable( + reference.pointer, + _id_methodGenericFirstOfNullable as _$jni.JMethodIDPtr, + _$list.pointer) + .object<$V>(V); + } + + static final _id_stringListOf = _class.instanceMethodId( + r'stringListOf', + r'(Ljava/lang/String;)Ljava/util/List;', + ); + + static final _stringListOf = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final java.util.List stringListOf(java.lang.String string)` + /// The returned object must be released after use, by calling the [release] method. + _$jni.JList<_$jni.JString> stringListOf( + _$jni.JString string, + ) { + final _$string = string.reference; + return _stringListOf(reference.pointer, + _id_stringListOf as _$jni.JMethodIDPtr, _$string.pointer) + .object<_$jni.JList<_$jni.JString>>( + const _$jni.JListType<_$jni.JString>(_$jni.JStringType())); + } + + static final _id_nullableListOf = _class.instanceMethodId( + r'nullableListOf', + r'(Ljava/lang/String;)Ljava/util/List;', + ); + + static final _nullableListOf = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final java.util.List nullableListOf(java.lang.String string)` + /// The returned object must be released after use, by calling the [release] method. + _$jni.JList<_$jni.JString?> nullableListOf( + _$jni.JString? string, + ) { + final _$string = string?.reference ?? _$jni.jNullReference; + return _nullableListOf(reference.pointer, + _id_nullableListOf as _$jni.JMethodIDPtr, _$string.pointer) + .object<_$jni.JList<_$jni.JString?>>( + const _$jni.JListType<_$jni.JString?>(_$jni.JStringNullableType())); + } + + static final _id_classGenericListOf = _class.instanceMethodId( + r'classGenericListOf', + r'(Ljava/lang/Object;)Ljava/util/List;', + ); + + static final _classGenericListOf = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final java.util.List classGenericListOf(U object)` + /// The returned object must be released after use, by calling the [release] method. + _$jni.JList<$U> classGenericListOf( + $U object, + ) { + final _$object = object.reference; + return _classGenericListOf(reference.pointer, + _id_classGenericListOf as _$jni.JMethodIDPtr, _$object.pointer) + .object<_$jni.JList<$U>>(_$jni.JListType<$U>(U)); + } + + static final _id_classGenericNullableListOf = _class.instanceMethodId( + r'classGenericNullableListOf', + r'(Ljava/lang/Object;)Ljava/util/List;', + ); + + static final _classGenericNullableListOf = + _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final java.util.List classGenericNullableListOf(T object)` + /// The returned object must be released after use, by calling the [release] method. + _$jni.JList<$T> classGenericNullableListOf( + $T object, + ) { + final _$object = object?.reference ?? _$jni.jNullReference; + return _classGenericNullableListOf( + reference.pointer, + _id_classGenericNullableListOf as _$jni.JMethodIDPtr, + _$object.pointer) + .object<_$jni.JList<$T>>(_$jni.JListType<$T>(T)); + } + + static final _id_methodGenericListOf = _class.instanceMethodId( + r'methodGenericListOf', + r'(Ljava/lang/Object;)Ljava/util/List;', + ); + + static final _methodGenericListOf = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final java.util.List methodGenericListOf(V object)` + /// The returned object must be released after use, by calling the [release] method. + _$jni.JList<$V> methodGenericListOf<$V extends _$jni.JObject>( + $V object, { + _$jni.JObjType<$V>? V, + }) { + V ??= _$jni.lowestCommonSuperType([ + object.$type, + ]) as _$jni.JObjType<$V>; + final _$object = object.reference; + return _methodGenericListOf(reference.pointer, + _id_methodGenericListOf as _$jni.JMethodIDPtr, _$object.pointer) + .object<_$jni.JList<$V>>(_$jni.JListType<$V>(V)); + } + + static final _id_methodGenericNullableListOf = _class.instanceMethodId( + r'methodGenericNullableListOf', + r'(Ljava/lang/Object;)Ljava/util/List;', + ); + + static final _methodGenericNullableListOf = + _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final java.util.List methodGenericNullableListOf(V object)` + /// The returned object must be released after use, by calling the [release] method. + _$jni.JList<$V> methodGenericNullableListOf<$V extends _$jni.JObject?>( + $V object, { + required _$jni.JObjType<$V> V, + }) { + final _$object = object?.reference ?? _$jni.jNullReference; + return _methodGenericNullableListOf( + reference.pointer, + _id_methodGenericNullableListOf as _$jni.JMethodIDPtr, + _$object.pointer) + .object<_$jni.JList<$V>>(_$jni.JListType<$V>(V)); + } +} + +final class $Nullability$NullableType<$T extends _$jni.JObject?, + $U extends _$jni.JObject> extends _$jni.JObjType?> { + @_$jni.internal + final _$jni.JObjType<$T> T; + + @_$jni.internal + final _$jni.JObjType<$U> U; + + @_$jni.internal + const $Nullability$NullableType( + this.T, + this.U, + ); + + @_$jni.internal + @_$core.override + String get signature => r'Lcom/github/dart_lang/jnigen/Nullability;'; + + @_$jni.internal + @_$core.override + Nullability<$T, $U>? fromReference(_$jni.JReference reference) => + reference.isNull + ? null + : Nullability<$T, $U>.fromReference( + T, + U, + reference, + ); + @_$jni.internal + @_$core.override + _$jni.JObjType get superType => const _$jni.JObjectType(); + + @_$jni.internal + @_$core.override + _$jni.JObjType?> get nullableType => this; + + @_$jni.internal + @_$core.override + final superCount = 1; + + @_$core.override + int get hashCode => Object.hash($Nullability$NullableType, T, U); + + @_$core.override + bool operator ==(Object other) { + return other.runtimeType == ($Nullability$NullableType<$T, $U>) && + other is $Nullability$NullableType<$T, $U> && + T == other.T && + U == other.U; + } +} + +final class $Nullability$Type<$T extends _$jni.JObject?, + $U extends _$jni.JObject> extends _$jni.JObjType> { + @_$jni.internal + final _$jni.JObjType<$T> T; + + @_$jni.internal + final _$jni.JObjType<$U> U; + + @_$jni.internal + const $Nullability$Type( + this.T, + this.U, + ); + + @_$jni.internal + @_$core.override + String get signature => r'Lcom/github/dart_lang/jnigen/Nullability;'; + + @_$jni.internal + @_$core.override + Nullability<$T, $U> fromReference(_$jni.JReference reference) => + Nullability<$T, $U>.fromReference( + T, + U, + reference, + ); + @_$jni.internal + @_$core.override + _$jni.JObjType get superType => const _$jni.JObjectType(); + + @_$jni.internal + @_$core.override + _$jni.JObjType?> get nullableType => + $Nullability$NullableType<$T, $U>(T, U); + + @_$jni.internal + @_$core.override + final superCount = 1; + + @_$core.override + int get hashCode => Object.hash($Nullability$Type, T, U); + + @_$core.override + bool operator ==(Object other) { + return other.runtimeType == ($Nullability$Type<$T, $U>) && + other is $Nullability$Type<$T, $U> && + T == other.T && + U == other.U; + } +} + +/// from: `com.github.dart_lang.jnigen.Nullabilty$InnerClass` +class Nullabilty_InnerClass< + $T extends _$jni.JObject?, + $U extends _$jni.JObject?, + $V extends _$jni.JObject?> extends _$jni.JObject { + @_$jni.internal + @_$core.override + final _$jni.JObjType> $type; + + @_$jni.internal + final _$jni.JObjType<$T> T; + + @_$jni.internal + final _$jni.JObjType<$U> U; + + @_$jni.internal + final _$jni.JObjType<$V> V; + + @_$jni.internal + Nullabilty_InnerClass.fromReference( + this.T, + this.U, + this.V, + _$jni.JReference reference, + ) : $type = type<$T, $U, $V>(T, U, V), + super.fromReference(reference); + + static final _class = _$jni.JClass.forName( + r'com/github/dart_lang/jnigen/Nullabilty$InnerClass'); + + /// The type which includes information such as the signature of this class. + static $Nullabilty_InnerClass$NullableType<$T, $U, $V> nullableType< + $T extends _$jni.JObject?, + $U extends _$jni.JObject?, + $V extends _$jni.JObject?>( + _$jni.JObjType<$T> T, + _$jni.JObjType<$U> U, + _$jni.JObjType<$V> V, + ) { + return $Nullabilty_InnerClass$NullableType<$T, $U, $V>( + T, + U, + V, + ); + } + + static $Nullabilty_InnerClass$Type<$T, $U, $V> type<$T extends _$jni.JObject?, + $U extends _$jni.JObject?, $V extends _$jni.JObject?>( + _$jni.JObjType<$T> T, + _$jni.JObjType<$U> U, + _$jni.JObjType<$V> V, + ) { + return $Nullabilty_InnerClass$Type<$T, $U, $V>( + T, + U, + V, + ); + } + + static final _id_new$ = _class.constructorId( + r'(Lcom/github/dart_lang/jnigen/Nullabilty;)V', + ); + + static final _new$ = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_NewObject') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public void (com.github.dart_lang.jnigen.Nullabilty $outerClass)` + /// The returned object must be released after use, by calling the [release] method. + factory Nullabilty_InnerClass( + Nullabilty<$T?, $U?> $outerClass, { + _$jni.JObjType<$T>? T, + _$jni.JObjType<$U>? U, + required _$jni.JObjType<$V> V, + }) { + T ??= _$jni.lowestCommonSuperType([ + ($outerClass.$type as $Nullabilty$Type<_$core.dynamic, _$core.dynamic>).T, + ]) as _$jni.JObjType<$T>; + U ??= _$jni.lowestCommonSuperType([ + ($outerClass.$type as $Nullabilty$Type<_$core.dynamic, _$core.dynamic>).U, + ]) as _$jni.JObjType<$U>; + final _$$outerClass = $outerClass.reference; + return Nullabilty_InnerClass<$T, $U, $V>.fromReference( + T, + U, + V, + _new$(_class.reference.pointer, _id_new$ as _$jni.JMethodIDPtr, + _$$outerClass.pointer) + .reference); + } + + static final _id_f = _class.instanceMethodId( + r'f', + r'(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V', + ); + + static final _f = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JThrowablePtr Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs< + ( + _$jni.Pointer<_$jni.Void>, + _$jni.Pointer<_$jni.Void>, + _$jni.Pointer<_$jni.Void> + )>)>>('globalEnv_CallVoidMethod') + .asFunction< + _$jni.JThrowablePtr Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.Pointer<_$jni.Void>, + _$jni.Pointer<_$jni.Void>, + _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final void f(T object, U object1, V object2)` + void f( + $T object, + $U object1, + $V object2, + ) { + final _$object = object?.reference ?? _$jni.jNullReference; + final _$object1 = object1?.reference ?? _$jni.jNullReference; + final _$object2 = object2?.reference ?? _$jni.jNullReference; + _f(reference.pointer, _id_f as _$jni.JMethodIDPtr, _$object.pointer, + _$object1.pointer, _$object2.pointer) + .check(); + } +} + +final class $Nullabilty_InnerClass$NullableType<$T extends _$jni.JObject?, + $U extends _$jni.JObject?, $V extends _$jni.JObject?> + extends _$jni.JObjType?> { + @_$jni.internal + final _$jni.JObjType<$T> T; + + @_$jni.internal + final _$jni.JObjType<$U> U; + + @_$jni.internal + final _$jni.JObjType<$V> V; + + @_$jni.internal + const $Nullabilty_InnerClass$NullableType( + this.T, + this.U, + this.V, + ); + + @_$jni.internal + @_$core.override + String get signature => + r'Lcom/github/dart_lang/jnigen/Nullabilty$InnerClass;'; + + @_$jni.internal + @_$core.override + Nullabilty_InnerClass<$T, $U, $V>? fromReference( + _$jni.JReference reference) => + reference.isNull + ? null + : Nullabilty_InnerClass<$T, $U, $V>.fromReference( + T, + U, + V, + reference, + ); + @_$jni.internal + @_$core.override + _$jni.JObjType get superType => const _$jni.JObjectType(); + + @_$jni.internal + @_$core.override + _$jni.JObjType?> get nullableType => this; + + @_$jni.internal + @_$core.override + final superCount = 1; + + @_$core.override + int get hashCode => Object.hash($Nullabilty_InnerClass$NullableType, T, U, V); + + @_$core.override + bool operator ==(Object other) { + return other.runtimeType == + ($Nullabilty_InnerClass$NullableType<$T, $U, $V>) && + other is $Nullabilty_InnerClass$NullableType<$T, $U, $V> && + T == other.T && + U == other.U && + V == other.V; + } +} + +final class $Nullabilty_InnerClass$Type<$T extends _$jni.JObject?, + $U extends _$jni.JObject?, $V extends _$jni.JObject?> + extends _$jni.JObjType> { + @_$jni.internal + final _$jni.JObjType<$T> T; + + @_$jni.internal + final _$jni.JObjType<$U> U; + + @_$jni.internal + final _$jni.JObjType<$V> V; + + @_$jni.internal + const $Nullabilty_InnerClass$Type( + this.T, + this.U, + this.V, + ); + + @_$jni.internal + @_$core.override + String get signature => + r'Lcom/github/dart_lang/jnigen/Nullabilty$InnerClass;'; + + @_$jni.internal + @_$core.override + Nullabilty_InnerClass<$T, $U, $V> fromReference(_$jni.JReference reference) => + Nullabilty_InnerClass<$T, $U, $V>.fromReference( + T, + U, + V, + reference, + ); + @_$jni.internal + @_$core.override + _$jni.JObjType get superType => const _$jni.JObjectType(); + + @_$jni.internal + @_$core.override + _$jni.JObjType?> get nullableType => + $Nullabilty_InnerClass$NullableType<$T, $U, $V>(T, U, V); + + @_$jni.internal + @_$core.override + final superCount = 1; + + @_$core.override + int get hashCode => Object.hash($Nullabilty_InnerClass$Type, T, U, V); + + @_$core.override + bool operator ==(Object other) { + return other.runtimeType == ($Nullabilty_InnerClass$Type<$T, $U, $V>) && + other is $Nullabilty_InnerClass$Type<$T, $U, $V> && + T == other.T && + U == other.U && + V == other.V; + } +} + +/// from: `com.github.dart_lang.jnigen.Nullabilty` +class Nullabilty<$T extends _$jni.JObject?, $U extends _$jni.JObject?> + extends _$jni.JObject { + @_$jni.internal + @_$core.override + final _$jni.JObjType> $type; + + @_$jni.internal + final _$jni.JObjType<$T> T; + + @_$jni.internal + final _$jni.JObjType<$U> U; + + @_$jni.internal + Nullabilty.fromReference( + this.T, + this.U, + _$jni.JReference reference, + ) : $type = type<$T, $U>(T, U), + super.fromReference(reference); + + static final _class = + _$jni.JClass.forName(r'com/github/dart_lang/jnigen/Nullabilty'); + + /// The type which includes information such as the signature of this class. + static $Nullabilty$NullableType<$T, $U> + nullableType<$T extends _$jni.JObject?, $U extends _$jni.JObject?>( + _$jni.JObjType<$T> T, + _$jni.JObjType<$U> U, + ) { + return $Nullabilty$NullableType<$T, $U>( + T, + U, + ); + } + + static $Nullabilty$Type<$T, $U> + type<$T extends _$jni.JObject?, $U extends _$jni.JObject?>( + _$jni.JObjType<$T> T, + _$jni.JObjType<$U> U, + ) { + return $Nullabilty$Type<$T, $U>( + T, + U, + ); + } + + static final _id_new$ = _class.constructorId( + r'(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V', + ); + + static final _new$ = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs< + ( + _$jni.Pointer<_$jni.Void>, + _$jni.Pointer<_$jni.Void>, + _$jni.Pointer<_$jni.Void> + )>)>>('globalEnv_NewObject') + .asFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.Pointer<_$jni.Void>, + _$jni.Pointer<_$jni.Void>, + _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public void (T object, U object1, U object2)` + /// The returned object must be released after use, by calling the [release] method. + factory Nullabilty( + $T object, + $U object1, + $U? object2, { + required _$jni.JObjType<$T> T, + required _$jni.JObjType<$U> U, + }) { + final _$object = object?.reference ?? _$jni.jNullReference; + final _$object1 = object1?.reference ?? _$jni.jNullReference; + final _$object2 = object2?.reference ?? _$jni.jNullReference; + return Nullabilty<$T, $U>.fromReference( + T, + U, + _new$(_class.reference.pointer, _id_new$ as _$jni.JMethodIDPtr, + _$object.pointer, _$object1.pointer, _$object2.pointer) + .reference); + } + + static final _id_getT = _class.instanceMethodId( + r'getT', + r'()Ljava/lang/Object;', + ); + + static final _getT = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + )>>('globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + )>(); + + /// from: `public final T getT()` + /// The returned object must be released after use, by calling the [release] method. + $T getT() { + return _getT(reference.pointer, _id_getT as _$jni.JMethodIDPtr) + .object<$T>(T); + } + + static final _id_getU = _class.instanceMethodId( + r'getU', + r'()Ljava/lang/Object;', + ); + + static final _getU = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + )>>('globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + )>(); + + /// from: `public final U getU()` + /// The returned object must be released after use, by calling the [release] method. + $U getU() { + return _getU(reference.pointer, _id_getU as _$jni.JMethodIDPtr) + .object<$U>(U); + } + + static final _id_getNullableU = _class.instanceMethodId( + r'getNullableU', + r'()Ljava/lang/Object;', + ); + + static final _getNullableU = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + )>>('globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + )>(); + + /// from: `public final U getNullableU()` + /// The returned object must be released after use, by calling the [release] method. + $U? getNullableU() { + return _getNullableU( + reference.pointer, _id_getNullableU as _$jni.JMethodIDPtr) + .object<$U?>(U.nullableType); + } + + static final _id_setNullableU = _class.instanceMethodId( + r'setNullableU', + r'(Ljava/lang/Object;)V', + ); + + static final _setNullableU = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JThrowablePtr Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallVoidMethod') + .asFunction< + _$jni.JThrowablePtr Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final void setNullableU(U object)` + void setNullableU( + $U? object, + ) { + final _$object = object?.reference ?? _$jni.jNullReference; + _setNullableU(reference.pointer, _id_setNullableU as _$jni.JMethodIDPtr, + _$object.pointer) + .check(); + } + + static final _id_hello = _class.instanceMethodId( + r'hello', + r'()Ljava/lang/String;', + ); + + static final _hello = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + )>>('globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + )>(); + + /// from: `public final java.lang.String hello()` + /// The returned object must be released after use, by calling the [release] method. + _$jni.JString hello() { + return _hello(reference.pointer, _id_hello as _$jni.JMethodIDPtr) + .object<_$jni.JString>(const _$jni.JStringType()); + } + + static final _id_nullableHello = _class.instanceMethodId( + r'nullableHello', + r'(Z)Ljava/lang/String;', + ); + + static final _nullableHello = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Int32,)>)>>('globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, _$jni.JMethodIDPtr, int)>(); + + /// from: `public final java.lang.String nullableHello(boolean z)` + /// The returned object must be released after use, by calling the [release] method. + _$jni.JString? nullableHello( + bool z, + ) { + return _nullableHello(reference.pointer, + _id_nullableHello as _$jni.JMethodIDPtr, z ? 1 : 0) + .object<_$jni.JString?>(const _$jni.JStringNullableType()); + } + + static final _id_methodGenericEcho = _class.instanceMethodId( + r'methodGenericEcho', + r'(Ljava/lang/Object;)Ljava/lang/Object;', + ); + + static final _methodGenericEcho = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final V methodGenericEcho(V object)` + /// The returned object must be released after use, by calling the [release] method. + $V methodGenericEcho<$V extends _$jni.JObject?>( + $V object, { + required _$jni.JObjType<$V> V, + }) { + final _$object = object?.reference ?? _$jni.jNullReference; + return _methodGenericEcho(reference.pointer, + _id_methodGenericEcho as _$jni.JMethodIDPtr, _$object.pointer) + .object<$V>(V); + } + + static final _id_methodGenericNullableEcho = _class.instanceMethodId( + r'methodGenericNullableEcho', + r'(Ljava/lang/Object;)Ljava/lang/Object;', + ); + + static final _methodGenericNullableEcho = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final V methodGenericNullableEcho(V object)` + /// The returned object must be released after use, by calling the [release] method. + $V methodGenericNullableEcho<$V extends _$jni.JObject?>( + $V object, { + required _$jni.JObjType<$V> V, + }) { + final _$object = object?.reference ?? _$jni.jNullReference; + return _methodGenericNullableEcho( + reference.pointer, + _id_methodGenericNullableEcho as _$jni.JMethodIDPtr, + _$object.pointer) + .object<$V>(V); + } + + static final _id_classGenericEcho = _class.instanceMethodId( + r'classGenericEcho', + r'(Ljava/lang/Object;)Ljava/lang/Object;', + ); + + static final _classGenericEcho = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final U classGenericEcho(U object)` + /// The returned object must be released after use, by calling the [release] method. + $U classGenericEcho( + $U object, + ) { + final _$object = object?.reference ?? _$jni.jNullReference; + return _classGenericEcho(reference.pointer, + _id_classGenericEcho as _$jni.JMethodIDPtr, _$object.pointer) + .object<$U>(U); + } + + static final _id_classGenericNullableEcho = _class.instanceMethodId( + r'classGenericNullableEcho', + r'(Ljava/lang/Object;)Ljava/lang/Object;', + ); + + static final _classGenericNullableEcho = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final T classGenericNullableEcho(T object)` + /// The returned object must be released after use, by calling the [release] method. + $T classGenericNullableEcho( + $T object, + ) { + final _$object = object?.reference ?? _$jni.jNullReference; + return _classGenericNullableEcho( + reference.pointer, + _id_classGenericNullableEcho as _$jni.JMethodIDPtr, + _$object.pointer) + .object<$T>(T); + } + + static final _id_firstOf = _class.instanceMethodId( + r'firstOf', + r'(Ljava/util/List;)Ljava/lang/String;', + ); + + static final _firstOf = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final java.lang.String firstOf(java.util.List list)` + /// The returned object must be released after use, by calling the [release] method. + _$jni.JString firstOf( + _$jni.JList<_$jni.JString> list, + ) { + final _$list = list.reference; + return _firstOf(reference.pointer, _id_firstOf as _$jni.JMethodIDPtr, + _$list.pointer) + .object<_$jni.JString>(const _$jni.JStringType()); + } + + static final _id_firstOfNullable = _class.instanceMethodId( + r'firstOfNullable', + r'(Ljava/util/List;)Ljava/lang/String;', + ); + + static final _firstOfNullable = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final java.lang.String firstOfNullable(java.util.List list)` + /// The returned object must be released after use, by calling the [release] method. + _$jni.JString? firstOfNullable( + _$jni.JList<_$jni.JString?> list, + ) { + final _$list = list.reference; + return _firstOfNullable(reference.pointer, + _id_firstOfNullable as _$jni.JMethodIDPtr, _$list.pointer) + .object<_$jni.JString?>(const _$jni.JStringNullableType()); + } + + static final _id_classGenericFirstOf = _class.instanceMethodId( + r'classGenericFirstOf', + r'(Ljava/util/List;)Ljava/lang/Object;', + ); + + static final _classGenericFirstOf = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final U classGenericFirstOf(java.util.List list)` + /// The returned object must be released after use, by calling the [release] method. + $U classGenericFirstOf( + _$jni.JList<$U> list, + ) { + final _$list = list.reference; + return _classGenericFirstOf(reference.pointer, + _id_classGenericFirstOf as _$jni.JMethodIDPtr, _$list.pointer) + .object<$U>(U); + } + + static final _id_classGenericFirstOfNullable = _class.instanceMethodId( + r'classGenericFirstOfNullable', + r'(Ljava/util/List;)Ljava/lang/Object;', + ); + + static final _classGenericFirstOfNullable = + _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final T classGenericFirstOfNullable(java.util.List list)` + /// The returned object must be released after use, by calling the [release] method. + $T classGenericFirstOfNullable( + _$jni.JList<$T> list, + ) { + final _$list = list.reference; + return _classGenericFirstOfNullable( + reference.pointer, + _id_classGenericFirstOfNullable as _$jni.JMethodIDPtr, + _$list.pointer) + .object<$T>(T); + } + + static final _id_methodGenericFirstOf = _class.instanceMethodId( + r'methodGenericFirstOf', + r'(Ljava/util/List;)Ljava/lang/Object;', + ); + + static final _methodGenericFirstOf = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final V methodGenericFirstOf(java.util.List list)` + /// The returned object must be released after use, by calling the [release] method. + $V methodGenericFirstOf<$V extends _$jni.JObject?>( + _$jni.JList<$V> list, { + _$jni.JObjType<$V>? V, + }) { + V ??= _$jni.lowestCommonSuperType([ + (list.$type as _$jni.JListType<_$core.dynamic>).E, + ]) as _$jni.JObjType<$V>; + final _$list = list.reference; + return _methodGenericFirstOf(reference.pointer, + _id_methodGenericFirstOf as _$jni.JMethodIDPtr, _$list.pointer) + .object<$V>(V); + } + + static final _id_methodGenericFirstOfNullable = _class.instanceMethodId( + r'methodGenericFirstOfNullable', + r'(Ljava/util/List;)Ljava/lang/Object;', + ); + + static final _methodGenericFirstOfNullable = + _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final V methodGenericFirstOfNullable(java.util.List list)` + /// The returned object must be released after use, by calling the [release] method. + $V methodGenericFirstOfNullable<$V extends _$jni.JObject?>( + _$jni.JList<$V> list, { + _$jni.JObjType<$V>? V, + }) { + V ??= _$jni.lowestCommonSuperType([ + (list.$type as _$jni.JListType<_$core.dynamic>).E, + ]) as _$jni.JObjType<$V>; + final _$list = list.reference; + return _methodGenericFirstOfNullable( + reference.pointer, + _id_methodGenericFirstOfNullable as _$jni.JMethodIDPtr, + _$list.pointer) + .object<$V>(V); + } + + static final _id_stringListOf = _class.instanceMethodId( + r'stringListOf', + r'(Ljava/lang/String;)Ljava/util/List;', + ); + + static final _stringListOf = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final java.util.List stringListOf(java.lang.String string)` + /// The returned object must be released after use, by calling the [release] method. + _$jni.JList<_$jni.JString> stringListOf( + _$jni.JString string, + ) { + final _$string = string.reference; + return _stringListOf(reference.pointer, + _id_stringListOf as _$jni.JMethodIDPtr, _$string.pointer) + .object<_$jni.JList<_$jni.JString>>( + const _$jni.JListType<_$jni.JString>(_$jni.JStringType())); + } + + static final _id_nullableListOf = _class.instanceMethodId( + r'nullableListOf', + r'(Ljava/lang/String;)Ljava/util/List;', + ); + + static final _nullableListOf = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final java.util.List nullableListOf(java.lang.String string)` + /// The returned object must be released after use, by calling the [release] method. + _$jni.JList<_$jni.JString?> nullableListOf( + _$jni.JString? string, + ) { + final _$string = string?.reference ?? _$jni.jNullReference; + return _nullableListOf(reference.pointer, + _id_nullableListOf as _$jni.JMethodIDPtr, _$string.pointer) + .object<_$jni.JList<_$jni.JString?>>( + const _$jni.JListType<_$jni.JString?>(_$jni.JStringNullableType())); + } + + static final _id_classGenericListOf = _class.instanceMethodId( + r'classGenericListOf', + r'(Ljava/lang/Object;)Ljava/util/List;', + ); + + static final _classGenericListOf = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final java.util.List classGenericListOf(U object)` + /// The returned object must be released after use, by calling the [release] method. + _$jni.JList<$U> classGenericListOf( + $U object, + ) { + final _$object = object?.reference ?? _$jni.jNullReference; + return _classGenericListOf(reference.pointer, + _id_classGenericListOf as _$jni.JMethodIDPtr, _$object.pointer) + .object<_$jni.JList<$U>>(_$jni.JListType<$U>(U)); + } + + static final _id_classGenericNullableListOf = _class.instanceMethodId( + r'classGenericNullableListOf', + r'(Ljava/lang/Object;)Ljava/util/List;', + ); + + static final _classGenericNullableListOf = + _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final java.util.List classGenericNullableListOf(T object)` + /// The returned object must be released after use, by calling the [release] method. + _$jni.JList<$T> classGenericNullableListOf( + $T object, + ) { + final _$object = object?.reference ?? _$jni.jNullReference; + return _classGenericNullableListOf( + reference.pointer, + _id_classGenericNullableListOf as _$jni.JMethodIDPtr, + _$object.pointer) + .object<_$jni.JList<$T>>(_$jni.JListType<$T>(T)); + } + + static final _id_methodGenericListOf = _class.instanceMethodId( + r'methodGenericListOf', + r'(Ljava/lang/Object;)Ljava/util/List;', + ); + + static final _methodGenericListOf = _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final java.util.List methodGenericListOf(V object)` + /// The returned object must be released after use, by calling the [release] method. + _$jni.JList<$V> methodGenericListOf<$V extends _$jni.JObject?>( + $V object, { + required _$jni.JObjType<$V> V, + }) { + final _$object = object?.reference ?? _$jni.jNullReference; + return _methodGenericListOf(reference.pointer, + _id_methodGenericListOf as _$jni.JMethodIDPtr, _$object.pointer) + .object<_$jni.JList<$V>>(_$jni.JListType<$V>(V)); + } + + static final _id_methodGenericNullableListOf = _class.instanceMethodId( + r'methodGenericNullableListOf', + r'(Ljava/lang/Object;)Ljava/util/List;', + ); + + static final _methodGenericNullableListOf = + _$jni.ProtectedJniExtensions.lookup< + _$jni.NativeFunction< + _$jni.JniResult Function( + _$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, + _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( + 'globalEnv_CallObjectMethod') + .asFunction< + _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, + _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); + + /// from: `public final java.util.List methodGenericNullableListOf(V object)` + /// The returned object must be released after use, by calling the [release] method. + _$jni.JList<$V> methodGenericNullableListOf<$V extends _$jni.JObject?>( + $V object, { + required _$jni.JObjType<$V> V, + }) { + final _$object = object?.reference ?? _$jni.jNullReference; + return _methodGenericNullableListOf( + reference.pointer, + _id_methodGenericNullableListOf as _$jni.JMethodIDPtr, + _$object.pointer) + .object<_$jni.JList<$V>>(_$jni.JListType<$V>(V)); + } } final class $Nullabilty$NullableType<$T extends _$jni.JObject?, @@ -1132,7 +2555,7 @@ final class $Nullabilty$NullableType<$T extends _$jni.JObject?, ); @_$jni.internal @_$core.override - _$jni.JObjType get superType => const _$jni.JObjectNullableType(); + _$jni.JObjType get superType => const _$jni.JObjectType(); @_$jni.internal @_$core.override @@ -1182,7 +2605,7 @@ final class $Nullabilty$Type<$T extends _$jni.JObject?, ); @_$jni.internal @_$core.override - _$jni.JObjType get superType => const _$jni.JObjectNullableType(); + _$jni.JObjType get superType => const _$jni.JObjectType(); @_$jni.internal @_$core.override @@ -1206,7 +2629,7 @@ final class $Nullabilty$Type<$T extends _$jni.JObject?, } /// from: `com.github.dart_lang.jnigen.Speed` -class Speed extends Measure { +class Speed extends Measure { @_$jni.internal @_$core.override final _$jni.JObjType $type; @@ -1215,7 +2638,7 @@ class Speed extends Measure { Speed.fromReference( _$jni.JReference reference, ) : $type = type, - super.fromReference(const $SpeedUnit$NullableType(), reference); + super.fromReference(const $SpeedUnit$Type(), reference); static final _class = _$jni.JClass.forName(r'com/github/dart_lang/jnigen/Speed'); @@ -1470,7 +2893,7 @@ final class $Speed$NullableType extends _$jni.JObjType { @_$jni.internal @_$core.override _$jni.JObjType get superType => - const $Measure$NullableType($SpeedUnit$NullableType()); + const $Measure$Type($SpeedUnit$Type()); @_$jni.internal @_$core.override @@ -1506,7 +2929,7 @@ final class $Speed$Type extends _$jni.JObjType { @_$jni.internal @_$core.override _$jni.JObjType get superType => - const $Measure$NullableType($SpeedUnit$NullableType()); + const $Measure$Type($SpeedUnit$Type()); @_$jni.internal @_$core.override @@ -1682,7 +3105,7 @@ final class $SpeedUnit$NullableType extends _$jni.JObjType { ); @_$jni.internal @_$core.override - _$jni.JObjType get superType => const _$jni.JObjectNullableType(); + _$jni.JObjType get superType => const _$jni.JObjectType(); @_$jni.internal @_$core.override @@ -1718,7 +3141,7 @@ final class $SpeedUnit$Type extends _$jni.JObjType { ); @_$jni.internal @_$core.override - _$jni.JObjType get superType => const _$jni.JObjectNullableType(); + _$jni.JObjType get superType => const _$jni.JObjectType(); @_$jni.internal @_$core.override @@ -1880,7 +3303,7 @@ final class $SuspendFun$NullableType extends _$jni.JObjType { ); @_$jni.internal @_$core.override - _$jni.JObjType get superType => const _$jni.JObjectNullableType(); + _$jni.JObjType get superType => const _$jni.JObjectType(); @_$jni.internal @_$core.override @@ -1916,7 +3339,7 @@ final class $SuspendFun$Type extends _$jni.JObjType { ); @_$jni.internal @_$core.override - _$jni.JObjType get superType => const _$jni.JObjectNullableType(); + _$jni.JObjType get superType => const _$jni.JObjectType(); @_$jni.internal @_$core.override diff --git a/pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullability.kt b/pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullability.kt new file mode 100644 index 000000000..73a56dfa0 --- /dev/null +++ b/pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullability.kt @@ -0,0 +1,79 @@ +package com.github.dart_lang.jnigen + +class Nullability(val t: T, val u: U, var nullableU: U?) { + fun hello(): String { + return "hello" + } + + fun nullableHello(returnNull: Boolean): String? { + return if (returnNull) null else "hello" + } + + fun methodGenericEcho(v: V): V { + return v + } + + fun methodGenericNullableEcho(v: V): V { + return v + } + + fun classGenericEcho(u: U): U { + return u + } + + fun classGenericNullableEcho(t: T): T { + return t + } + + fun firstOf(list: List): String { + return list.first(); + } + + fun firstOfNullable(list: List): String? { + return list.first(); + } + + fun classGenericFirstOf(list: List): U { + return list.first(); + } + + fun classGenericFirstOfNullable(list: List): T { + return list.first(); + } + + fun methodGenericFirstOf(list: List): V { + return list.first(); + } + + fun methodGenericFirstOfNullable(list: List): V { + return list.first(); + } + + fun stringListOf(element: String): List { + return listOf(element) + } + + fun nullableListOf(element: String?): List { + return listOf(element) + } + + fun classGenericListOf(element: U): List { + return listOf(element) + } + + fun classGenericNullableListOf(element: T): List { + return listOf(element) + } + + fun methodGenericListOf(element: V): List { + return listOf(element) + } + + fun methodGenericNullableListOf(element: V): List { + return listOf(element) + } + + inner class InnerClass { + fun f(t: T, u: U, v: V) {} + } +} \ No newline at end of file diff --git a/pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullabilty.kt b/pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullabilty.kt deleted file mode 100644 index dded93259..000000000 --- a/pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullabilty.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.github.dart_lang.jnigen - -class Nullabilty(val t: T, val u: U, var nullableU: U?) { - fun hello(): String { - return "hello" - } - - fun nullableHello(returnNull: Boolean): String? { - return if (returnNull) null else "hello" - } - - fun methodGenericEcho(v: V): V { - return v - } - - fun methodGenericNullableEcho(v: V): V { - return v - } - - fun classGenericEcho(u: U): U { - return u - } - - fun classGenericNullableEcho(t: T): T { - return t - } - - inner class InnerClass { - fun f(t: T, u: U, v: V) {} - } -} \ No newline at end of file diff --git a/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart b/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart index a1368e947..d6f61e47b 100644 --- a/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart +++ b/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart @@ -33,13 +33,13 @@ void registerTests(String groupName, TestRunnerCallback test) { test('Generics', () { using((arena) { final speed = Speed(10, SpeedUnit.MetrePerSec!)..releasedBy(arena); - expect(speed.convertValue(SpeedUnit.KmPerHour), closeTo(36, 1e-6)); + expect(speed.convertValue(SpeedUnit.KmPerHour!), closeTo(36, 1e-6)); }); }); group('Nullability', () { - Nullabilty testObject(Arena arena) { - return Nullabilty( + Nullability testObject(Arena arena) { + return Nullability( null, 'hello'.toJString(), null, @@ -114,6 +114,117 @@ void registerTests(String groupName, TestRunnerCallback test) { obj.methodGenericNullableEcho(null, V: JString.nullableType), null, ); + expect( + obj + .stringListOf('hello'.toJString()..releasedBy(arena))[0] + .toDartString(releaseOriginal: true), + 'hello', + ); + expect( + obj + .nullableListOf('hello'.toJString()..releasedBy(arena))[0]! + .toDartString(releaseOriginal: true), + 'hello', + ); + expect(obj.nullableListOf(null)[0], null); + expect( + obj + .classGenericListOf('hello'.toJString()..releasedBy(arena))[0] + .toDartString(releaseOriginal: true), + 'hello', + ); + expect( + obj + .classGenericNullableListOf( + 'hello'.toJString()..releasedBy(arena))[0]! + .toDartString(releaseOriginal: true), + 'hello', + ); + expect(obj.classGenericNullableListOf(null)[0], null); + expect( + obj + .methodGenericListOf('hello'.toJString()..releasedBy(arena))[0] + .toDartString(releaseOriginal: true), + 'hello', + ); + expect( + obj + .methodGenericNullableListOf( + 'hello'.toJString()..releasedBy(arena), + V: JString.nullableType, + )[0]! + .toDartString(releaseOriginal: true), + 'hello', + ); + expect( + obj.methodGenericNullableListOf(null, V: JString.nullableType)[0], + null, + ); + expect( + obj + .firstOf(['hello'.toJString()..releasedBy(arena)] + .toJList(JString.type)) + .toDartString(releaseOriginal: true), + 'hello', + ); + expect( + obj + .firstOfNullable(['hello'.toJString()..releasedBy(arena), null] + .toJList(JString.nullableType))! + .toDartString(releaseOriginal: true), + 'hello', + ); + expect( + obj.firstOfNullable([null, 'hello'.toJString()..releasedBy(arena)] + .toJList(JString.nullableType)), + null, + ); + expect( + obj + .classGenericFirstOf(['hello'.toJString()..releasedBy(arena)] + .toJList(JString.type)) + .toDartString(releaseOriginal: true), + 'hello', + ); + expect( + obj + .classGenericFirstOfNullable([ + 'hello'.toJString()..releasedBy(arena), + null, + ].toJList(JString.nullableType))! + .toDartString(releaseOriginal: true), + 'hello', + ); + expect( + obj.classGenericFirstOfNullable([ + null, + 'hello'.toJString()..releasedBy(arena), + ].toJList(JString.nullableType)), + null, + ); + expect( + obj + .methodGenericFirstOf(['hello'.toJString()..releasedBy(arena)] + .toJList(JString.type)) + .toDartString(releaseOriginal: true), + 'hello', + ); + expect( + obj + .methodGenericFirstOfNullable([ + 'hello'.toJString()..releasedBy(arena), + null, + ].toJList(JString.nullableType))! + .toDartString(releaseOriginal: true), + 'hello', + ); + expect( + obj.methodGenericFirstOfNullable([ + null, + 'hello'.toJString()..releasedBy(arena), + ].toJList(JString.nullableType)), + null, + ); }); }); }); From b6542a0e69770ac9bb1ea04ba0756f49d0dd3a9f Mon Sep 17 00:00:00 2001 From: Hossein Yousefi Date: Thu, 28 Nov 2024 19:16:11 +0100 Subject: [PATCH 05/13] Java format --- .../jnigen/apisummarizer/elements/KotlinTypeParameter.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/elements/KotlinTypeParameter.java b/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/elements/KotlinTypeParameter.java index 74f94afe8..449aef16c 100644 --- a/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/elements/KotlinTypeParameter.java +++ b/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/elements/KotlinTypeParameter.java @@ -6,8 +6,6 @@ import java.util.List; import java.util.stream.Collectors; - -import kotlinx.metadata.Flag; import kotlinx.metadata.KmTypeParameter; import kotlinx.metadata.KmVariance; From d87bbedfe655a0813e2e1029b988d6040fde8f26 Mon Sep 17 00:00:00 2001 From: Hossein Yousefi Date: Thu, 28 Nov 2024 19:18:53 +0100 Subject: [PATCH 06/13] Java format --- .../dart_lang/jnigen/apisummarizer/elements/KotlinType.java | 1 - 1 file changed, 1 deletion(-) diff --git a/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/elements/KotlinType.java b/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/elements/KotlinType.java index 6ed80d741..69af1b9ee 100644 --- a/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/elements/KotlinType.java +++ b/pkgs/jnigen/java/src/main/java/com/github/dart_lang/jnigen/apisummarizer/elements/KotlinType.java @@ -6,7 +6,6 @@ import java.util.List; import java.util.stream.Collectors; - import kotlinx.metadata.Flag; import kotlinx.metadata.KmClassifier; import kotlinx.metadata.KmType; From 112d650803f7e1e0235f2782110df92ee7d24be9 Mon Sep 17 00:00:00 2001 From: Hossein Yousefi Date: Thu, 28 Nov 2024 19:29:49 +0100 Subject: [PATCH 07/13] Add inner class test --- .../com/github/dart_lang/jnigen/Nullability.kt | 2 +- .../test/kotlin_test/runtime_test_registrant.dart | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullability.kt b/pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullability.kt index 73a56dfa0..243ddab51 100644 --- a/pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullability.kt +++ b/pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullability.kt @@ -76,4 +76,4 @@ class Nullability(val t: T, val u: U, var nullableU: U?) { inner class InnerClass { fun f(t: T, u: U, v: V) {} } -} \ No newline at end of file +} diff --git a/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart b/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart index d6f61e47b..7d7ac1ff9 100644 --- a/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart +++ b/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart @@ -226,6 +226,18 @@ void registerTests(String groupName, TestRunnerCallback test) { null, ); }); + test('Inner class', () { + using((arena) { + final obj = testObject(arena); + final innerObj = + Nullability_InnerClass(obj, + V: JInteger.type); + expect( + innerObj.f, + isA(), + ); + }); + }); }); }); }); From 2b595d4232d1bd15417f81309c0e588a837e9bee Mon Sep 17 00:00:00 2001 From: Hossein Yousefi Date: Thu, 28 Nov 2024 19:37:10 +0100 Subject: [PATCH 08/13] Fix setters --- pkgs/jnigen/lib/src/bindings/kotlin_processor.dart | 4 ++-- pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart | 4 ++-- pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pkgs/jnigen/lib/src/bindings/kotlin_processor.dart b/pkgs/jnigen/lib/src/bindings/kotlin_processor.dart index 6c46ab63c..4772f06bb 100644 --- a/pkgs/jnigen/lib/src/bindings/kotlin_processor.dart +++ b/pkgs/jnigen/lib/src/bindings/kotlin_processor.dart @@ -184,9 +184,9 @@ class _KotlinSetterProcessor extends Visitor { @override void visit(Method node) { if (setter.setterParameter case final setterParam?) { - node.returnType.accept(_KotlinTypeProcessor(setterParam.type)); + node.params.single.type.accept(_KotlinTypeProcessor(setterParam.type)); } - node.returnType.accept(_KotlinTypeProcessor(setter.returnType)); + node.params.single.type.accept(_KotlinTypeProcessor(setter.returnType)); } } diff --git a/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart b/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart index a61bd3ce0..4301f998d 100644 --- a/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart +++ b/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart @@ -33,8 +33,8 @@ // ignore_for_file: unused_shown_name // ignore_for_file: use_super_parameters -import 'dart:core' as _$core; import 'dart:core' show Object, String, bool, double, int; +import 'dart:core' as _$core; import 'package:jni/_internal.dart' as _$jni; import 'package:jni/jni.dart' as _$jni; @@ -937,7 +937,7 @@ class Nullability<$T extends _$jni.JObject?, $U extends _$jni.JObject> /// from: `public final void setNullableU(U object)` void setNullableU( - $U object, + $U? object, ) { final _$object = object?.reference ?? _$jni.jNullReference; _setNullableU(reference.pointer, _id_setNullableU as _$jni.JMethodIDPtr, diff --git a/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart b/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart index 7d7ac1ff9..fc9a33527 100644 --- a/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart +++ b/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart @@ -67,6 +67,11 @@ void registerTests(String groupName, TestRunnerCallback test) { obj.getNullableU()!.toDartString(releaseOriginal: true), 'hello', ); + obj.setNullableU(null); + expect( + obj.getNullableU(), + null, + ); }); }); test('Methods', () { From 6a37c0a2a70e8d450aeaa64be9ec22a475c59194 Mon Sep 17 00:00:00 2001 From: Hossein Yousefi Date: Thu, 28 Nov 2024 19:54:59 +0100 Subject: [PATCH 09/13] Gracefully fail for superclasses --- .../lib/src/bindings/kotlin_processor.dart | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pkgs/jnigen/lib/src/bindings/kotlin_processor.dart b/pkgs/jnigen/lib/src/bindings/kotlin_processor.dart index 4772f06bb..e76e9f58c 100644 --- a/pkgs/jnigen/lib/src/bindings/kotlin_processor.dart +++ b/pkgs/jnigen/lib/src/bindings/kotlin_processor.dart @@ -6,7 +6,8 @@ import '../elements/elements.dart'; import 'visitor.dart'; String _toJavaBinaryName(String kotlinBinaryName) { - final binaryName = kotlinBinaryName.replaceAll('/', '.'); + final binaryName = + kotlinBinaryName.replaceAll('.', r'$').replaceAll('/', '.'); return const { 'kotlin.Any': 'java.lang.Object', 'kotlin.Byte': 'java.lang.Byte', @@ -53,10 +54,15 @@ class _KotlinClassProcessor extends Visitor { node.typeParams[i].accept( _KotlinTypeParamProcessor(node.kotlinClass!.typeParameters[i])); } - node.superclass?.accept(_KotlinTypeProcessor( - node.kotlinClass!.superTypes.firstWhere((superType) => - _toJavaBinaryName(superType.name ?? '') == node.superclass!.name), - )); + if (node.superclass case final superClass?) { + final kotlinSuperTypes = node.kotlinClass!.superTypes.where( + (superType) => + _toJavaBinaryName(superType.name ?? '') == superClass.name, + ); + if (kotlinSuperTypes.isNotEmpty) { + superClass.accept(_KotlinTypeProcessor(kotlinSuperTypes.single)); + } + } } // Matching fields and properties from the metadata. From 74326c79de52fa26cf33cc23860a51ff8bd86dee Mon Sep 17 00:00:00 2001 From: Hossein Yousefi Date: Thu, 28 Nov 2024 20:21:34 +0100 Subject: [PATCH 10/13] Fix suspend funs --- .../kotlin_plugin/example/lib/main.dart | 4 ++-- .../kotlin_plugin/lib/kotlin_bindings.dart | 12 +++++----- .../lib/src/bindings/kotlin_processor.dart | 22 ++++++++++++++++--- .../test/kotlin_test/bindings/kotlin.dart | 12 +++++----- .../kotlin_test/runtime_test_registrant.dart | 4 ++-- 5 files changed, 35 insertions(+), 19 deletions(-) diff --git a/pkgs/jnigen/example/kotlin_plugin/example/lib/main.dart b/pkgs/jnigen/example/kotlin_plugin/example/lib/main.dart index a7e671ef8..84a91337c 100644 --- a/pkgs/jnigen/example/kotlin_plugin/example/lib/main.dart +++ b/pkgs/jnigen/example/kotlin_plugin/example/lib/main.dart @@ -62,8 +62,8 @@ class _MyHomePageState extends State { ElevatedButton( onPressed: () { setState(() { - answer = example.thinkBeforeAnswering().then((value) => - value?.toDartString(releaseOriginal: true) ?? 'null'); + answer = example.thinkBeforeAnswering().then( + (value) => value.toDartString(releaseOriginal: true)); }); }, child: const Text('Think...'), diff --git a/pkgs/jnigen/example/kotlin_plugin/lib/kotlin_bindings.dart b/pkgs/jnigen/example/kotlin_plugin/lib/kotlin_bindings.dart index 60b859b65..fceb46300 100644 --- a/pkgs/jnigen/example/kotlin_plugin/lib/kotlin_bindings.dart +++ b/pkgs/jnigen/example/kotlin_plugin/lib/kotlin_bindings.dart @@ -94,7 +94,7 @@ class Example extends _$jni.JObject { /// from: `public final java.lang.Object thinkBeforeAnswering(kotlin.coroutines.Continuation continuation)` /// The returned object must be released after use, by calling the [release] method. - _$core.Future<_$jni.JString?> thinkBeforeAnswering() async { + _$core.Future<_$jni.JString> thinkBeforeAnswering() async { final $p = _$jni.ReceivePort(); final _$continuation = _$jni.ProtectedJniExtensions.newPortContinuation($p); @@ -102,17 +102,17 @@ class Example extends _$jni.JObject { reference.pointer, _id_thinkBeforeAnswering as _$jni.JMethodIDPtr, _$continuation.pointer) - .object<_$jni.JObject?>(const _$jni.JObjectNullableType()); + .object<_$jni.JObject>(const _$jni.JObjectType()); _$continuation.release(); final $o = _$jni.JGlobalReference(_$jni.JObjectPtr.fromAddress(await $p.first)); - final $k = const _$jni.JStringNullableType().jClass.reference; + final $k = const _$jni.JStringType().jClass.reference; if (!_$jni.Jni.env.IsInstanceOf($o.pointer, $k.pointer)) { $k.release(); throw 'Failed'; } $k.release(); - return const _$jni.JStringNullableType().fromReference($o); + return const _$jni.JStringType().fromReference($o); } } @@ -133,7 +133,7 @@ final class $Example$NullableType extends _$jni.JObjType { ); @_$jni.internal @_$core.override - _$jni.JObjType get superType => const _$jni.JObjectNullableType(); + _$jni.JObjType get superType => const _$jni.JObjectType(); @_$jni.internal @_$core.override @@ -168,7 +168,7 @@ final class $Example$Type extends _$jni.JObjType { ); @_$jni.internal @_$core.override - _$jni.JObjType get superType => const _$jni.JObjectNullableType(); + _$jni.JObjType get superType => const _$jni.JObjectType(); @_$jni.internal @_$core.override diff --git a/pkgs/jnigen/lib/src/bindings/kotlin_processor.dart b/pkgs/jnigen/lib/src/bindings/kotlin_processor.dart index e76e9f58c..b1539fa94 100644 --- a/pkgs/jnigen/lib/src/bindings/kotlin_processor.dart +++ b/pkgs/jnigen/lib/src/bindings/kotlin_processor.dart @@ -135,7 +135,6 @@ class _KotlinMethodProcessor extends Visitor { @override void visit(Method node) { - node.returnType.accept(_KotlinTypeProcessor(function.returnType)); _processParams(node.params, function.valueParameters); for (var i = 0; i < node.typeParams.length; ++i) { node.typeParams[i] @@ -156,6 +155,13 @@ class _KotlinMethodProcessor extends Visitor { node.asyncReturnType = continuationType == null ? TypeUsage.object : continuationType.clone(); + node.asyncReturnType!.accept(_KotlinTypeProcessor(function.returnType)); + + // The continuation object is always non-null. + node.returnType.type.annotations ??= []; + node.returnType.type.annotations!.add(Annotation.nonNull); + } else { + node.returnType.accept(_KotlinTypeProcessor(function.returnType)); } } } @@ -255,8 +261,18 @@ class _KotlinTypeProcessor extends TypeVisitor { @override void visitArrayType(ArrayType node) { - node.elementType - .accept(_KotlinTypeProcessor(kotlinType.arguments.first.type)); + if (kotlinType.arguments.isNotEmpty) { + node.elementType + .accept(_KotlinTypeProcessor(kotlinType.arguments.first.type)); + } + super.visitArrayType(node); + } + + @override + void visitWildcard(Wildcard node) { + node.extendsBound?.accept(_KotlinTypeProcessor(kotlinType)); + node.superBound?.accept(_KotlinTypeProcessor(kotlinType)); + super.visitWildcard(node); } @override diff --git a/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart b/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart index 4301f998d..32c656b88 100644 --- a/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart +++ b/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart @@ -3221,7 +3221,7 @@ class SuspendFun extends _$jni.JObject { /// from: `public final java.lang.Object sayHello(kotlin.coroutines.Continuation continuation)` /// The returned object must be released after use, by calling the [release] method. - _$core.Future<_$jni.JString?> sayHello() async { + _$core.Future<_$jni.JString> sayHello() async { final $p = _$jni.ReceivePort(); final _$continuation = _$jni.ProtectedJniExtensions.newPortContinuation($p); @@ -3231,13 +3231,13 @@ class SuspendFun extends _$jni.JObject { _$continuation.release(); final $o = _$jni.JGlobalReference(_$jni.JObjectPtr.fromAddress(await $p.first)); - final $k = const _$jni.JStringNullableType().jClass.reference; + final $k = const _$jni.JStringType().jClass.reference; if (!_$jni.Jni.env.IsInstanceOf($o.pointer, $k.pointer)) { $k.release(); throw 'Failed'; } $k.release(); - return const _$jni.JStringNullableType().fromReference($o); + return const _$jni.JStringType().fromReference($o); } static final _id_sayHello$1 = _class.instanceMethodId( @@ -3264,7 +3264,7 @@ class SuspendFun extends _$jni.JObject { /// from: `public final java.lang.Object sayHello(java.lang.String string, kotlin.coroutines.Continuation continuation)` /// The returned object must be released after use, by calling the [release] method. - _$core.Future<_$jni.JString?> sayHello$1( + _$core.Future<_$jni.JString> sayHello$1( _$jni.JString? string, ) async { final $p = _$jni.ReceivePort(); @@ -3276,13 +3276,13 @@ class SuspendFun extends _$jni.JObject { _$continuation.release(); final $o = _$jni.JGlobalReference(_$jni.JObjectPtr.fromAddress(await $p.first)); - final $k = const _$jni.JStringNullableType().jClass.reference; + final $k = const _$jni.JStringType().jClass.reference; if (!_$jni.Jni.env.IsInstanceOf($o.pointer, $k.pointer)) { $k.release(); throw 'Failed'; } $k.release(); - return const _$jni.JStringNullableType().fromReference($o); + return const _$jni.JStringType().fromReference($o); } } diff --git a/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart b/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart index fc9a33527..73e3cc82c 100644 --- a/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart +++ b/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart @@ -13,11 +13,11 @@ void registerTests(String groupName, TestRunnerCallback test) { test('Suspend functions', () async { await using((arena) async { final suspendFun = SuspendFun()..releasedBy(arena); - final hello = (await suspendFun.sayHello())!; + final hello = await suspendFun.sayHello(); expect(hello.toDartString(releaseOriginal: true), 'Hello!'); const name = 'Bob'; final helloBob = - (await suspendFun.sayHello$1(name.toJString()..releasedBy(arena)))!; + await suspendFun.sayHello$1(name.toJString()..releasedBy(arena)); expect(helloBob.toDartString(releaseOriginal: true), 'Hello $name!'); }); }); From 2440e1a9b2b6c82a5761484aacfa1ef9eb2fdd9b Mon Sep 17 00:00:00 2001 From: Hossein Yousefi Date: Fri, 29 Nov 2024 01:18:28 +0100 Subject: [PATCH 11/13] Fix tests --- .../kotlin_test/runtime_test_registrant.dart | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart b/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart index 73e3cc82c..aceef678f 100644 --- a/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart +++ b/pkgs/jnigen/test/kotlin_test/runtime_test_registrant.dart @@ -231,17 +231,17 @@ void registerTests(String groupName, TestRunnerCallback test) { null, ); }); - test('Inner class', () { - using((arena) { - final obj = testObject(arena); - final innerObj = - Nullability_InnerClass(obj, - V: JInteger.type); - expect( - innerObj.f, - isA(), - ); - }); + }); + test('Inner class', () { + using((arena) { + final obj = testObject(arena); + final innerObj = Nullability_InnerClass( + obj, + V: JInteger.type); + expect( + innerObj.f, + isA(), + ); }); }); }); From 8f090da798aae38b95a7c40bd568e01c27b15236 Mon Sep 17 00:00:00 2001 From: Hossein Yousefi Date: Fri, 29 Nov 2024 01:20:22 +0100 Subject: [PATCH 12/13] Make everything public, even though should be by default! --- .../github/dart_lang/jnigen/Nullability.kt | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullability.kt b/pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullability.kt index 243ddab51..41da4d9bc 100644 --- a/pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullability.kt +++ b/pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullability.kt @@ -1,79 +1,79 @@ package com.github.dart_lang.jnigen -class Nullability(val t: T, val u: U, var nullableU: U?) { - fun hello(): String { +public class Nullability(val t: T, val u: U, var nullableU: U?) { + public fun hello(): String { return "hello" } - fun nullableHello(returnNull: Boolean): String? { + public fun nullableHello(returnNull: Boolean): String? { return if (returnNull) null else "hello" } - fun methodGenericEcho(v: V): V { + public fun methodGenericEcho(v: V): V { return v } - fun methodGenericNullableEcho(v: V): V { + public fun methodGenericNullableEcho(v: V): V { return v } - fun classGenericEcho(u: U): U { + public fun classGenericEcho(u: U): U { return u } - fun classGenericNullableEcho(t: T): T { + public fun classGenericNullableEcho(t: T): T { return t } - fun firstOf(list: List): String { + public fun firstOf(list: List): String { return list.first(); } - fun firstOfNullable(list: List): String? { + public fun firstOfNullable(list: List): String? { return list.first(); } - fun classGenericFirstOf(list: List): U { + public fun classGenericFirstOf(list: List): U { return list.first(); } - fun classGenericFirstOfNullable(list: List): T { + public fun classGenericFirstOfNullable(list: List): T { return list.first(); } - fun methodGenericFirstOf(list: List): V { + public fun methodGenericFirstOf(list: List): V { return list.first(); } - fun methodGenericFirstOfNullable(list: List): V { + public fun methodGenericFirstOfNullable(list: List): V { return list.first(); } - fun stringListOf(element: String): List { + public fun stringListOf(element: String): List { return listOf(element) } - fun nullableListOf(element: String?): List { + public fun nullableListOf(element: String?): List { return listOf(element) } - fun classGenericListOf(element: U): List { + public fun classGenericListOf(element: U): List { return listOf(element) } - fun classGenericNullableListOf(element: T): List { + public fun classGenericNullableListOf(element: T): List { return listOf(element) } - fun methodGenericListOf(element: V): List { + public fun methodGenericListOf(element: V): List { return listOf(element) } - fun methodGenericNullableListOf(element: V): List { + public fun methodGenericNullableListOf(element: V): List { return listOf(element) } - inner class InnerClass { - fun f(t: T, u: U, v: V) {} + public inner class InnerClass { + public fun f(t: T, u: U, v: V) {} } } From 89f3b6e12b6147172493421e56517c4b22d8e588 Mon Sep 17 00:00:00 2001 From: Hossein Yousefi Date: Fri, 29 Nov 2024 21:32:59 +0100 Subject: [PATCH 13/13] Fix tests --- .../test/kotlin_test/bindings/kotlin.dart | 1062 ----------------- .../github/dart_lang/jnigen/Nullability.kt | 5 + 2 files changed, 5 insertions(+), 1062 deletions(-) diff --git a/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart b/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart index 32c656b88..d6769f1aa 100644 --- a/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart +++ b/pkgs/jnigen/test/kotlin_test/bindings/kotlin.dart @@ -1566,1068 +1566,6 @@ final class $Nullability$Type<$T extends _$jni.JObject?, } } -/// from: `com.github.dart_lang.jnigen.Nullabilty$InnerClass` -class Nullabilty_InnerClass< - $T extends _$jni.JObject?, - $U extends _$jni.JObject?, - $V extends _$jni.JObject?> extends _$jni.JObject { - @_$jni.internal - @_$core.override - final _$jni.JObjType> $type; - - @_$jni.internal - final _$jni.JObjType<$T> T; - - @_$jni.internal - final _$jni.JObjType<$U> U; - - @_$jni.internal - final _$jni.JObjType<$V> V; - - @_$jni.internal - Nullabilty_InnerClass.fromReference( - this.T, - this.U, - this.V, - _$jni.JReference reference, - ) : $type = type<$T, $U, $V>(T, U, V), - super.fromReference(reference); - - static final _class = _$jni.JClass.forName( - r'com/github/dart_lang/jnigen/Nullabilty$InnerClass'); - - /// The type which includes information such as the signature of this class. - static $Nullabilty_InnerClass$NullableType<$T, $U, $V> nullableType< - $T extends _$jni.JObject?, - $U extends _$jni.JObject?, - $V extends _$jni.JObject?>( - _$jni.JObjType<$T> T, - _$jni.JObjType<$U> U, - _$jni.JObjType<$V> V, - ) { - return $Nullabilty_InnerClass$NullableType<$T, $U, $V>( - T, - U, - V, - ); - } - - static $Nullabilty_InnerClass$Type<$T, $U, $V> type<$T extends _$jni.JObject?, - $U extends _$jni.JObject?, $V extends _$jni.JObject?>( - _$jni.JObjType<$T> T, - _$jni.JObjType<$U> U, - _$jni.JObjType<$V> V, - ) { - return $Nullabilty_InnerClass$Type<$T, $U, $V>( - T, - U, - V, - ); - } - - static final _id_new$ = _class.constructorId( - r'(Lcom/github/dart_lang/jnigen/Nullabilty;)V', - ); - - static final _new$ = _$jni.ProtectedJniExtensions.lookup< - _$jni.NativeFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( - 'globalEnv_NewObject') - .asFunction< - _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); - - /// from: `public void (com.github.dart_lang.jnigen.Nullabilty $outerClass)` - /// The returned object must be released after use, by calling the [release] method. - factory Nullabilty_InnerClass( - Nullabilty<$T?, $U?> $outerClass, { - _$jni.JObjType<$T>? T, - _$jni.JObjType<$U>? U, - required _$jni.JObjType<$V> V, - }) { - T ??= _$jni.lowestCommonSuperType([ - ($outerClass.$type as $Nullabilty$Type<_$core.dynamic, _$core.dynamic>).T, - ]) as _$jni.JObjType<$T>; - U ??= _$jni.lowestCommonSuperType([ - ($outerClass.$type as $Nullabilty$Type<_$core.dynamic, _$core.dynamic>).U, - ]) as _$jni.JObjType<$U>; - final _$$outerClass = $outerClass.reference; - return Nullabilty_InnerClass<$T, $U, $V>.fromReference( - T, - U, - V, - _new$(_class.reference.pointer, _id_new$ as _$jni.JMethodIDPtr, - _$$outerClass.pointer) - .reference); - } - - static final _id_f = _class.instanceMethodId( - r'f', - r'(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V', - ); - - static final _f = _$jni.ProtectedJniExtensions.lookup< - _$jni.NativeFunction< - _$jni.JThrowablePtr Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - _$jni.VarArgs< - ( - _$jni.Pointer<_$jni.Void>, - _$jni.Pointer<_$jni.Void>, - _$jni.Pointer<_$jni.Void> - )>)>>('globalEnv_CallVoidMethod') - .asFunction< - _$jni.JThrowablePtr Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - _$jni.Pointer<_$jni.Void>, - _$jni.Pointer<_$jni.Void>, - _$jni.Pointer<_$jni.Void>)>(); - - /// from: `public final void f(T object, U object1, V object2)` - void f( - $T object, - $U object1, - $V object2, - ) { - final _$object = object?.reference ?? _$jni.jNullReference; - final _$object1 = object1?.reference ?? _$jni.jNullReference; - final _$object2 = object2?.reference ?? _$jni.jNullReference; - _f(reference.pointer, _id_f as _$jni.JMethodIDPtr, _$object.pointer, - _$object1.pointer, _$object2.pointer) - .check(); - } -} - -final class $Nullabilty_InnerClass$NullableType<$T extends _$jni.JObject?, - $U extends _$jni.JObject?, $V extends _$jni.JObject?> - extends _$jni.JObjType?> { - @_$jni.internal - final _$jni.JObjType<$T> T; - - @_$jni.internal - final _$jni.JObjType<$U> U; - - @_$jni.internal - final _$jni.JObjType<$V> V; - - @_$jni.internal - const $Nullabilty_InnerClass$NullableType( - this.T, - this.U, - this.V, - ); - - @_$jni.internal - @_$core.override - String get signature => - r'Lcom/github/dart_lang/jnigen/Nullabilty$InnerClass;'; - - @_$jni.internal - @_$core.override - Nullabilty_InnerClass<$T, $U, $V>? fromReference( - _$jni.JReference reference) => - reference.isNull - ? null - : Nullabilty_InnerClass<$T, $U, $V>.fromReference( - T, - U, - V, - reference, - ); - @_$jni.internal - @_$core.override - _$jni.JObjType get superType => const _$jni.JObjectType(); - - @_$jni.internal - @_$core.override - _$jni.JObjType?> get nullableType => this; - - @_$jni.internal - @_$core.override - final superCount = 1; - - @_$core.override - int get hashCode => Object.hash($Nullabilty_InnerClass$NullableType, T, U, V); - - @_$core.override - bool operator ==(Object other) { - return other.runtimeType == - ($Nullabilty_InnerClass$NullableType<$T, $U, $V>) && - other is $Nullabilty_InnerClass$NullableType<$T, $U, $V> && - T == other.T && - U == other.U && - V == other.V; - } -} - -final class $Nullabilty_InnerClass$Type<$T extends _$jni.JObject?, - $U extends _$jni.JObject?, $V extends _$jni.JObject?> - extends _$jni.JObjType> { - @_$jni.internal - final _$jni.JObjType<$T> T; - - @_$jni.internal - final _$jni.JObjType<$U> U; - - @_$jni.internal - final _$jni.JObjType<$V> V; - - @_$jni.internal - const $Nullabilty_InnerClass$Type( - this.T, - this.U, - this.V, - ); - - @_$jni.internal - @_$core.override - String get signature => - r'Lcom/github/dart_lang/jnigen/Nullabilty$InnerClass;'; - - @_$jni.internal - @_$core.override - Nullabilty_InnerClass<$T, $U, $V> fromReference(_$jni.JReference reference) => - Nullabilty_InnerClass<$T, $U, $V>.fromReference( - T, - U, - V, - reference, - ); - @_$jni.internal - @_$core.override - _$jni.JObjType get superType => const _$jni.JObjectType(); - - @_$jni.internal - @_$core.override - _$jni.JObjType?> get nullableType => - $Nullabilty_InnerClass$NullableType<$T, $U, $V>(T, U, V); - - @_$jni.internal - @_$core.override - final superCount = 1; - - @_$core.override - int get hashCode => Object.hash($Nullabilty_InnerClass$Type, T, U, V); - - @_$core.override - bool operator ==(Object other) { - return other.runtimeType == ($Nullabilty_InnerClass$Type<$T, $U, $V>) && - other is $Nullabilty_InnerClass$Type<$T, $U, $V> && - T == other.T && - U == other.U && - V == other.V; - } -} - -/// from: `com.github.dart_lang.jnigen.Nullabilty` -class Nullabilty<$T extends _$jni.JObject?, $U extends _$jni.JObject?> - extends _$jni.JObject { - @_$jni.internal - @_$core.override - final _$jni.JObjType> $type; - - @_$jni.internal - final _$jni.JObjType<$T> T; - - @_$jni.internal - final _$jni.JObjType<$U> U; - - @_$jni.internal - Nullabilty.fromReference( - this.T, - this.U, - _$jni.JReference reference, - ) : $type = type<$T, $U>(T, U), - super.fromReference(reference); - - static final _class = - _$jni.JClass.forName(r'com/github/dart_lang/jnigen/Nullabilty'); - - /// The type which includes information such as the signature of this class. - static $Nullabilty$NullableType<$T, $U> - nullableType<$T extends _$jni.JObject?, $U extends _$jni.JObject?>( - _$jni.JObjType<$T> T, - _$jni.JObjType<$U> U, - ) { - return $Nullabilty$NullableType<$T, $U>( - T, - U, - ); - } - - static $Nullabilty$Type<$T, $U> - type<$T extends _$jni.JObject?, $U extends _$jni.JObject?>( - _$jni.JObjType<$T> T, - _$jni.JObjType<$U> U, - ) { - return $Nullabilty$Type<$T, $U>( - T, - U, - ); - } - - static final _id_new$ = _class.constructorId( - r'(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V', - ); - - static final _new$ = _$jni.ProtectedJniExtensions.lookup< - _$jni.NativeFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - _$jni.VarArgs< - ( - _$jni.Pointer<_$jni.Void>, - _$jni.Pointer<_$jni.Void>, - _$jni.Pointer<_$jni.Void> - )>)>>('globalEnv_NewObject') - .asFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - _$jni.Pointer<_$jni.Void>, - _$jni.Pointer<_$jni.Void>, - _$jni.Pointer<_$jni.Void>)>(); - - /// from: `public void (T object, U object1, U object2)` - /// The returned object must be released after use, by calling the [release] method. - factory Nullabilty( - $T object, - $U object1, - $U? object2, { - required _$jni.JObjType<$T> T, - required _$jni.JObjType<$U> U, - }) { - final _$object = object?.reference ?? _$jni.jNullReference; - final _$object1 = object1?.reference ?? _$jni.jNullReference; - final _$object2 = object2?.reference ?? _$jni.jNullReference; - return Nullabilty<$T, $U>.fromReference( - T, - U, - _new$(_class.reference.pointer, _id_new$ as _$jni.JMethodIDPtr, - _$object.pointer, _$object1.pointer, _$object2.pointer) - .reference); - } - - static final _id_getT = _class.instanceMethodId( - r'getT', - r'()Ljava/lang/Object;', - ); - - static final _getT = _$jni.ProtectedJniExtensions.lookup< - _$jni.NativeFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - )>>('globalEnv_CallObjectMethod') - .asFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - )>(); - - /// from: `public final T getT()` - /// The returned object must be released after use, by calling the [release] method. - $T getT() { - return _getT(reference.pointer, _id_getT as _$jni.JMethodIDPtr) - .object<$T>(T); - } - - static final _id_getU = _class.instanceMethodId( - r'getU', - r'()Ljava/lang/Object;', - ); - - static final _getU = _$jni.ProtectedJniExtensions.lookup< - _$jni.NativeFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - )>>('globalEnv_CallObjectMethod') - .asFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - )>(); - - /// from: `public final U getU()` - /// The returned object must be released after use, by calling the [release] method. - $U getU() { - return _getU(reference.pointer, _id_getU as _$jni.JMethodIDPtr) - .object<$U>(U); - } - - static final _id_getNullableU = _class.instanceMethodId( - r'getNullableU', - r'()Ljava/lang/Object;', - ); - - static final _getNullableU = _$jni.ProtectedJniExtensions.lookup< - _$jni.NativeFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - )>>('globalEnv_CallObjectMethod') - .asFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - )>(); - - /// from: `public final U getNullableU()` - /// The returned object must be released after use, by calling the [release] method. - $U? getNullableU() { - return _getNullableU( - reference.pointer, _id_getNullableU as _$jni.JMethodIDPtr) - .object<$U?>(U.nullableType); - } - - static final _id_setNullableU = _class.instanceMethodId( - r'setNullableU', - r'(Ljava/lang/Object;)V', - ); - - static final _setNullableU = _$jni.ProtectedJniExtensions.lookup< - _$jni.NativeFunction< - _$jni.JThrowablePtr Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( - 'globalEnv_CallVoidMethod') - .asFunction< - _$jni.JThrowablePtr Function(_$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); - - /// from: `public final void setNullableU(U object)` - void setNullableU( - $U? object, - ) { - final _$object = object?.reference ?? _$jni.jNullReference; - _setNullableU(reference.pointer, _id_setNullableU as _$jni.JMethodIDPtr, - _$object.pointer) - .check(); - } - - static final _id_hello = _class.instanceMethodId( - r'hello', - r'()Ljava/lang/String;', - ); - - static final _hello = _$jni.ProtectedJniExtensions.lookup< - _$jni.NativeFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - )>>('globalEnv_CallObjectMethod') - .asFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - )>(); - - /// from: `public final java.lang.String hello()` - /// The returned object must be released after use, by calling the [release] method. - _$jni.JString hello() { - return _hello(reference.pointer, _id_hello as _$jni.JMethodIDPtr) - .object<_$jni.JString>(const _$jni.JStringType()); - } - - static final _id_nullableHello = _class.instanceMethodId( - r'nullableHello', - r'(Z)Ljava/lang/String;', - ); - - static final _nullableHello = _$jni.ProtectedJniExtensions.lookup< - _$jni.NativeFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - _$jni.VarArgs<(_$jni.Int32,)>)>>('globalEnv_CallObjectMethod') - .asFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, _$jni.JMethodIDPtr, int)>(); - - /// from: `public final java.lang.String nullableHello(boolean z)` - /// The returned object must be released after use, by calling the [release] method. - _$jni.JString? nullableHello( - bool z, - ) { - return _nullableHello(reference.pointer, - _id_nullableHello as _$jni.JMethodIDPtr, z ? 1 : 0) - .object<_$jni.JString?>(const _$jni.JStringNullableType()); - } - - static final _id_methodGenericEcho = _class.instanceMethodId( - r'methodGenericEcho', - r'(Ljava/lang/Object;)Ljava/lang/Object;', - ); - - static final _methodGenericEcho = _$jni.ProtectedJniExtensions.lookup< - _$jni.NativeFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( - 'globalEnv_CallObjectMethod') - .asFunction< - _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); - - /// from: `public final V methodGenericEcho(V object)` - /// The returned object must be released after use, by calling the [release] method. - $V methodGenericEcho<$V extends _$jni.JObject?>( - $V object, { - required _$jni.JObjType<$V> V, - }) { - final _$object = object?.reference ?? _$jni.jNullReference; - return _methodGenericEcho(reference.pointer, - _id_methodGenericEcho as _$jni.JMethodIDPtr, _$object.pointer) - .object<$V>(V); - } - - static final _id_methodGenericNullableEcho = _class.instanceMethodId( - r'methodGenericNullableEcho', - r'(Ljava/lang/Object;)Ljava/lang/Object;', - ); - - static final _methodGenericNullableEcho = _$jni.ProtectedJniExtensions.lookup< - _$jni.NativeFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( - 'globalEnv_CallObjectMethod') - .asFunction< - _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); - - /// from: `public final V methodGenericNullableEcho(V object)` - /// The returned object must be released after use, by calling the [release] method. - $V methodGenericNullableEcho<$V extends _$jni.JObject?>( - $V object, { - required _$jni.JObjType<$V> V, - }) { - final _$object = object?.reference ?? _$jni.jNullReference; - return _methodGenericNullableEcho( - reference.pointer, - _id_methodGenericNullableEcho as _$jni.JMethodIDPtr, - _$object.pointer) - .object<$V>(V); - } - - static final _id_classGenericEcho = _class.instanceMethodId( - r'classGenericEcho', - r'(Ljava/lang/Object;)Ljava/lang/Object;', - ); - - static final _classGenericEcho = _$jni.ProtectedJniExtensions.lookup< - _$jni.NativeFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( - 'globalEnv_CallObjectMethod') - .asFunction< - _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); - - /// from: `public final U classGenericEcho(U object)` - /// The returned object must be released after use, by calling the [release] method. - $U classGenericEcho( - $U object, - ) { - final _$object = object?.reference ?? _$jni.jNullReference; - return _classGenericEcho(reference.pointer, - _id_classGenericEcho as _$jni.JMethodIDPtr, _$object.pointer) - .object<$U>(U); - } - - static final _id_classGenericNullableEcho = _class.instanceMethodId( - r'classGenericNullableEcho', - r'(Ljava/lang/Object;)Ljava/lang/Object;', - ); - - static final _classGenericNullableEcho = _$jni.ProtectedJniExtensions.lookup< - _$jni.NativeFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( - 'globalEnv_CallObjectMethod') - .asFunction< - _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); - - /// from: `public final T classGenericNullableEcho(T object)` - /// The returned object must be released after use, by calling the [release] method. - $T classGenericNullableEcho( - $T object, - ) { - final _$object = object?.reference ?? _$jni.jNullReference; - return _classGenericNullableEcho( - reference.pointer, - _id_classGenericNullableEcho as _$jni.JMethodIDPtr, - _$object.pointer) - .object<$T>(T); - } - - static final _id_firstOf = _class.instanceMethodId( - r'firstOf', - r'(Ljava/util/List;)Ljava/lang/String;', - ); - - static final _firstOf = _$jni.ProtectedJniExtensions.lookup< - _$jni.NativeFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( - 'globalEnv_CallObjectMethod') - .asFunction< - _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); - - /// from: `public final java.lang.String firstOf(java.util.List list)` - /// The returned object must be released after use, by calling the [release] method. - _$jni.JString firstOf( - _$jni.JList<_$jni.JString> list, - ) { - final _$list = list.reference; - return _firstOf(reference.pointer, _id_firstOf as _$jni.JMethodIDPtr, - _$list.pointer) - .object<_$jni.JString>(const _$jni.JStringType()); - } - - static final _id_firstOfNullable = _class.instanceMethodId( - r'firstOfNullable', - r'(Ljava/util/List;)Ljava/lang/String;', - ); - - static final _firstOfNullable = _$jni.ProtectedJniExtensions.lookup< - _$jni.NativeFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( - 'globalEnv_CallObjectMethod') - .asFunction< - _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); - - /// from: `public final java.lang.String firstOfNullable(java.util.List list)` - /// The returned object must be released after use, by calling the [release] method. - _$jni.JString? firstOfNullable( - _$jni.JList<_$jni.JString?> list, - ) { - final _$list = list.reference; - return _firstOfNullable(reference.pointer, - _id_firstOfNullable as _$jni.JMethodIDPtr, _$list.pointer) - .object<_$jni.JString?>(const _$jni.JStringNullableType()); - } - - static final _id_classGenericFirstOf = _class.instanceMethodId( - r'classGenericFirstOf', - r'(Ljava/util/List;)Ljava/lang/Object;', - ); - - static final _classGenericFirstOf = _$jni.ProtectedJniExtensions.lookup< - _$jni.NativeFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( - 'globalEnv_CallObjectMethod') - .asFunction< - _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); - - /// from: `public final U classGenericFirstOf(java.util.List list)` - /// The returned object must be released after use, by calling the [release] method. - $U classGenericFirstOf( - _$jni.JList<$U> list, - ) { - final _$list = list.reference; - return _classGenericFirstOf(reference.pointer, - _id_classGenericFirstOf as _$jni.JMethodIDPtr, _$list.pointer) - .object<$U>(U); - } - - static final _id_classGenericFirstOfNullable = _class.instanceMethodId( - r'classGenericFirstOfNullable', - r'(Ljava/util/List;)Ljava/lang/Object;', - ); - - static final _classGenericFirstOfNullable = - _$jni.ProtectedJniExtensions.lookup< - _$jni.NativeFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( - 'globalEnv_CallObjectMethod') - .asFunction< - _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); - - /// from: `public final T classGenericFirstOfNullable(java.util.List list)` - /// The returned object must be released after use, by calling the [release] method. - $T classGenericFirstOfNullable( - _$jni.JList<$T> list, - ) { - final _$list = list.reference; - return _classGenericFirstOfNullable( - reference.pointer, - _id_classGenericFirstOfNullable as _$jni.JMethodIDPtr, - _$list.pointer) - .object<$T>(T); - } - - static final _id_methodGenericFirstOf = _class.instanceMethodId( - r'methodGenericFirstOf', - r'(Ljava/util/List;)Ljava/lang/Object;', - ); - - static final _methodGenericFirstOf = _$jni.ProtectedJniExtensions.lookup< - _$jni.NativeFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( - 'globalEnv_CallObjectMethod') - .asFunction< - _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); - - /// from: `public final V methodGenericFirstOf(java.util.List list)` - /// The returned object must be released after use, by calling the [release] method. - $V methodGenericFirstOf<$V extends _$jni.JObject?>( - _$jni.JList<$V> list, { - _$jni.JObjType<$V>? V, - }) { - V ??= _$jni.lowestCommonSuperType([ - (list.$type as _$jni.JListType<_$core.dynamic>).E, - ]) as _$jni.JObjType<$V>; - final _$list = list.reference; - return _methodGenericFirstOf(reference.pointer, - _id_methodGenericFirstOf as _$jni.JMethodIDPtr, _$list.pointer) - .object<$V>(V); - } - - static final _id_methodGenericFirstOfNullable = _class.instanceMethodId( - r'methodGenericFirstOfNullable', - r'(Ljava/util/List;)Ljava/lang/Object;', - ); - - static final _methodGenericFirstOfNullable = - _$jni.ProtectedJniExtensions.lookup< - _$jni.NativeFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( - 'globalEnv_CallObjectMethod') - .asFunction< - _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); - - /// from: `public final V methodGenericFirstOfNullable(java.util.List list)` - /// The returned object must be released after use, by calling the [release] method. - $V methodGenericFirstOfNullable<$V extends _$jni.JObject?>( - _$jni.JList<$V> list, { - _$jni.JObjType<$V>? V, - }) { - V ??= _$jni.lowestCommonSuperType([ - (list.$type as _$jni.JListType<_$core.dynamic>).E, - ]) as _$jni.JObjType<$V>; - final _$list = list.reference; - return _methodGenericFirstOfNullable( - reference.pointer, - _id_methodGenericFirstOfNullable as _$jni.JMethodIDPtr, - _$list.pointer) - .object<$V>(V); - } - - static final _id_stringListOf = _class.instanceMethodId( - r'stringListOf', - r'(Ljava/lang/String;)Ljava/util/List;', - ); - - static final _stringListOf = _$jni.ProtectedJniExtensions.lookup< - _$jni.NativeFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( - 'globalEnv_CallObjectMethod') - .asFunction< - _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); - - /// from: `public final java.util.List stringListOf(java.lang.String string)` - /// The returned object must be released after use, by calling the [release] method. - _$jni.JList<_$jni.JString> stringListOf( - _$jni.JString string, - ) { - final _$string = string.reference; - return _stringListOf(reference.pointer, - _id_stringListOf as _$jni.JMethodIDPtr, _$string.pointer) - .object<_$jni.JList<_$jni.JString>>( - const _$jni.JListType<_$jni.JString>(_$jni.JStringType())); - } - - static final _id_nullableListOf = _class.instanceMethodId( - r'nullableListOf', - r'(Ljava/lang/String;)Ljava/util/List;', - ); - - static final _nullableListOf = _$jni.ProtectedJniExtensions.lookup< - _$jni.NativeFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( - 'globalEnv_CallObjectMethod') - .asFunction< - _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); - - /// from: `public final java.util.List nullableListOf(java.lang.String string)` - /// The returned object must be released after use, by calling the [release] method. - _$jni.JList<_$jni.JString?> nullableListOf( - _$jni.JString? string, - ) { - final _$string = string?.reference ?? _$jni.jNullReference; - return _nullableListOf(reference.pointer, - _id_nullableListOf as _$jni.JMethodIDPtr, _$string.pointer) - .object<_$jni.JList<_$jni.JString?>>( - const _$jni.JListType<_$jni.JString?>(_$jni.JStringNullableType())); - } - - static final _id_classGenericListOf = _class.instanceMethodId( - r'classGenericListOf', - r'(Ljava/lang/Object;)Ljava/util/List;', - ); - - static final _classGenericListOf = _$jni.ProtectedJniExtensions.lookup< - _$jni.NativeFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( - 'globalEnv_CallObjectMethod') - .asFunction< - _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); - - /// from: `public final java.util.List classGenericListOf(U object)` - /// The returned object must be released after use, by calling the [release] method. - _$jni.JList<$U> classGenericListOf( - $U object, - ) { - final _$object = object?.reference ?? _$jni.jNullReference; - return _classGenericListOf(reference.pointer, - _id_classGenericListOf as _$jni.JMethodIDPtr, _$object.pointer) - .object<_$jni.JList<$U>>(_$jni.JListType<$U>(U)); - } - - static final _id_classGenericNullableListOf = _class.instanceMethodId( - r'classGenericNullableListOf', - r'(Ljava/lang/Object;)Ljava/util/List;', - ); - - static final _classGenericNullableListOf = - _$jni.ProtectedJniExtensions.lookup< - _$jni.NativeFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( - 'globalEnv_CallObjectMethod') - .asFunction< - _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); - - /// from: `public final java.util.List classGenericNullableListOf(T object)` - /// The returned object must be released after use, by calling the [release] method. - _$jni.JList<$T> classGenericNullableListOf( - $T object, - ) { - final _$object = object?.reference ?? _$jni.jNullReference; - return _classGenericNullableListOf( - reference.pointer, - _id_classGenericNullableListOf as _$jni.JMethodIDPtr, - _$object.pointer) - .object<_$jni.JList<$T>>(_$jni.JListType<$T>(T)); - } - - static final _id_methodGenericListOf = _class.instanceMethodId( - r'methodGenericListOf', - r'(Ljava/lang/Object;)Ljava/util/List;', - ); - - static final _methodGenericListOf = _$jni.ProtectedJniExtensions.lookup< - _$jni.NativeFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( - 'globalEnv_CallObjectMethod') - .asFunction< - _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); - - /// from: `public final java.util.List methodGenericListOf(V object)` - /// The returned object must be released after use, by calling the [release] method. - _$jni.JList<$V> methodGenericListOf<$V extends _$jni.JObject?>( - $V object, { - required _$jni.JObjType<$V> V, - }) { - final _$object = object?.reference ?? _$jni.jNullReference; - return _methodGenericListOf(reference.pointer, - _id_methodGenericListOf as _$jni.JMethodIDPtr, _$object.pointer) - .object<_$jni.JList<$V>>(_$jni.JListType<$V>(V)); - } - - static final _id_methodGenericNullableListOf = _class.instanceMethodId( - r'methodGenericNullableListOf', - r'(Ljava/lang/Object;)Ljava/util/List;', - ); - - static final _methodGenericNullableListOf = - _$jni.ProtectedJniExtensions.lookup< - _$jni.NativeFunction< - _$jni.JniResult Function( - _$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, - _$jni.VarArgs<(_$jni.Pointer<_$jni.Void>,)>)>>( - 'globalEnv_CallObjectMethod') - .asFunction< - _$jni.JniResult Function(_$jni.Pointer<_$jni.Void>, - _$jni.JMethodIDPtr, _$jni.Pointer<_$jni.Void>)>(); - - /// from: `public final java.util.List methodGenericNullableListOf(V object)` - /// The returned object must be released after use, by calling the [release] method. - _$jni.JList<$V> methodGenericNullableListOf<$V extends _$jni.JObject?>( - $V object, { - required _$jni.JObjType<$V> V, - }) { - final _$object = object?.reference ?? _$jni.jNullReference; - return _methodGenericNullableListOf( - reference.pointer, - _id_methodGenericNullableListOf as _$jni.JMethodIDPtr, - _$object.pointer) - .object<_$jni.JList<$V>>(_$jni.JListType<$V>(V)); - } -} - -final class $Nullabilty$NullableType<$T extends _$jni.JObject?, - $U extends _$jni.JObject?> extends _$jni.JObjType?> { - @_$jni.internal - final _$jni.JObjType<$T> T; - - @_$jni.internal - final _$jni.JObjType<$U> U; - - @_$jni.internal - const $Nullabilty$NullableType( - this.T, - this.U, - ); - - @_$jni.internal - @_$core.override - String get signature => r'Lcom/github/dart_lang/jnigen/Nullabilty;'; - - @_$jni.internal - @_$core.override - Nullabilty<$T, $U>? fromReference(_$jni.JReference reference) => - reference.isNull - ? null - : Nullabilty<$T, $U>.fromReference( - T, - U, - reference, - ); - @_$jni.internal - @_$core.override - _$jni.JObjType get superType => const _$jni.JObjectType(); - - @_$jni.internal - @_$core.override - _$jni.JObjType?> get nullableType => this; - - @_$jni.internal - @_$core.override - final superCount = 1; - - @_$core.override - int get hashCode => Object.hash($Nullabilty$NullableType, T, U); - - @_$core.override - bool operator ==(Object other) { - return other.runtimeType == ($Nullabilty$NullableType<$T, $U>) && - other is $Nullabilty$NullableType<$T, $U> && - T == other.T && - U == other.U; - } -} - -final class $Nullabilty$Type<$T extends _$jni.JObject?, - $U extends _$jni.JObject?> extends _$jni.JObjType> { - @_$jni.internal - final _$jni.JObjType<$T> T; - - @_$jni.internal - final _$jni.JObjType<$U> U; - - @_$jni.internal - const $Nullabilty$Type( - this.T, - this.U, - ); - - @_$jni.internal - @_$core.override - String get signature => r'Lcom/github/dart_lang/jnigen/Nullabilty;'; - - @_$jni.internal - @_$core.override - Nullabilty<$T, $U> fromReference(_$jni.JReference reference) => - Nullabilty<$T, $U>.fromReference( - T, - U, - reference, - ); - @_$jni.internal - @_$core.override - _$jni.JObjType get superType => const _$jni.JObjectType(); - - @_$jni.internal - @_$core.override - _$jni.JObjType?> get nullableType => - $Nullabilty$NullableType<$T, $U>(T, U); - - @_$jni.internal - @_$core.override - final superCount = 1; - - @_$core.override - int get hashCode => Object.hash($Nullabilty$Type, T, U); - - @_$core.override - bool operator ==(Object other) { - return other.runtimeType == ($Nullabilty$Type<$T, $U>) && - other is $Nullabilty$Type<$T, $U> && - T == other.T && - U == other.U; - } -} - /// from: `com.github.dart_lang.jnigen.Speed` class Speed extends Measure { @_$jni.internal diff --git a/pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullability.kt b/pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullability.kt index 41da4d9bc..159be46ba 100644 --- a/pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullability.kt +++ b/pkgs/jnigen/test/kotlin_test/kotlin/src/main/kotlin/com/github/dart_lang/jnigen/Nullability.kt @@ -1,3 +1,8 @@ +/* Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file + * for details. All rights reserved. Use of this source code is governed by a + * BSD-style license that can be found in the LICENSE file. + */ + package com.github.dart_lang.jnigen public class Nullability(val t: T, val u: U, var nullableU: U?) {