From 0010eca0c6c1602627a245b6803fa22430675363 Mon Sep 17 00:00:00 2001 From: Hossein Yousefi Date: Tue, 8 Oct 2024 13:15:33 +0200 Subject: [PATCH] Clone type usage --- .../lib/src/bindings/kotlin_processor.dart | 2 +- pkgs/jnigen/lib/src/elements/elements.dart | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/pkgs/jnigen/lib/src/bindings/kotlin_processor.dart b/pkgs/jnigen/lib/src/bindings/kotlin_processor.dart index b7d05f630..4980debf9 100644 --- a/pkgs/jnigen/lib/src/bindings/kotlin_processor.dart +++ b/pkgs/jnigen/lib/src/bindings/kotlin_processor.dart @@ -56,7 +56,7 @@ class _KotlinMethodProcessor extends Visitor { final continuationType = node.params.last.type.type as DeclaredType; node.asyncReturnType = continuationType.params.isEmpty ? TypeUsage.object - : continuationType.params.first; + : continuationType.params.first.clone(); } } } diff --git a/pkgs/jnigen/lib/src/elements/elements.dart b/pkgs/jnigen/lib/src/elements/elements.dart index 449c12e15..324fdc2b1 100644 --- a/pkgs/jnigen/lib/src/elements/elements.dart +++ b/pkgs/jnigen/lib/src/elements/elements.dart @@ -253,6 +253,30 @@ class TypeUsage { R accept(TypeVisitor v) { return type.accept(v); } + + TypeUsage clone() { + final ReferredType clonedType; + final clonedTypeJson = typeJson.map(MapEntry.new); + switch (kind) { + case Kind.primitive: + clonedType = PrimitiveType.fromJson(clonedTypeJson); + break; + case Kind.typeVariable: + clonedType = TypeVar.fromJson(clonedTypeJson); + break; + case Kind.wildcard: + clonedType = Wildcard.fromJson(clonedTypeJson); + break; + case Kind.declared: + clonedType = DeclaredType.fromJson(clonedTypeJson); + break; + case Kind.array: + clonedType = ArrayType.fromJson(clonedTypeJson); + break; + } + return TypeUsage(shorthand: shorthand, kind: kind, typeJson: clonedTypeJson) + ..type = clonedType; + } } abstract class ReferredType {