Skip to content

Commit

Permalink
Clone type usage
Browse files Browse the repository at this point in the history
  • Loading branch information
HosseinYousefi committed Oct 8, 2024
1 parent de23aec commit 0010eca
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkgs/jnigen/lib/src/bindings/kotlin_processor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class _KotlinMethodProcessor extends Visitor<Method, void> {
final continuationType = node.params.last.type.type as DeclaredType;
node.asyncReturnType = continuationType.params.isEmpty
? TypeUsage.object
: continuationType.params.first;
: continuationType.params.first.clone();
}
}
}
24 changes: 24 additions & 0 deletions pkgs/jnigen/lib/src/elements/elements.dart
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,30 @@ class TypeUsage {
R accept<R>(TypeVisitor<R> 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 {
Expand Down

0 comments on commit 0010eca

Please sign in to comment.