-
Notifications
You must be signed in to change notification settings - Fork 75
jextract: add support for arrays #435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
Samples/SwiftJavaExtractJNISampleApp/Sources/MySwiftLibrary/Arrays.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the Swift.org open source project | ||
| // | ||
| // Copyright (c) 2025 Apple Inc. and the Swift.org project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // See CONTRIBUTORS.txt for the list of Swift.org project authors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| import SwiftJava | ||
|
|
||
| public func booleanArray(array: [Bool]) -> [Bool] { | ||
| return array | ||
| } | ||
|
|
||
| public func byteArray(array: [UInt8]) -> [UInt8] { | ||
| return array | ||
| } | ||
|
|
||
| public func byteArrayExplicit(array: Array<UInt8>) -> Array<UInt8> { | ||
| return array | ||
| } | ||
|
|
||
| public func charArray(array: [UInt16]) -> [UInt16] { | ||
| return array | ||
| } | ||
|
|
||
| public func shortArray(array: [Int16]) -> [Int16] { | ||
| return array | ||
| } | ||
|
|
||
| public func intArray(array: [Int32]) -> [Int32] { | ||
| return array | ||
| } | ||
|
|
||
| public func longArray(array: [Int64]) -> [Int64] { | ||
| return array | ||
| } | ||
|
|
||
| public func floatArray(array: [Float]) -> [Float] { | ||
| return array | ||
| } | ||
|
|
||
| public func doubleArray(array: [Double]) -> [Double] { | ||
| return array | ||
| } | ||
|
|
||
| public func stringArray(array: [String]) -> [String] { | ||
| return array | ||
| } | ||
|
|
||
| public func objectArray(array: [MySwiftClass]) -> [MySwiftClass] { | ||
| return array | ||
| } | ||
|
|
105 changes: 105 additions & 0 deletions
105
Samples/SwiftJavaExtractJNISampleApp/src/test/java/com/example/swift/ArraysTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This source file is part of the Swift.org open source project | ||
| // | ||
| // Copyright (c) 2025 Apple Inc. and the Swift.org project authors | ||
| // Licensed under Apache License v2.0 | ||
| // | ||
| // See LICENSE.txt for license information | ||
| // See CONTRIBUTORS.txt for the list of Swift.org project authors | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| package com.example.swift; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.swift.swiftkit.core.SwiftArena; | ||
|
|
||
| import java.util.OptionalLong; | ||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.concurrent.ExecutionException; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| public class ArraysTest { | ||
| @Test | ||
| void booleanArray() { | ||
| boolean[] input = new boolean[] { true, false, false, true }; | ||
| assertArrayEquals(input, MySwiftLibrary.booleanArray(input)); | ||
| } | ||
|
|
||
| @Test | ||
| void byteArray() { | ||
| byte[] input = new byte[] { 10, 20, 30, 40 }; | ||
| assertArrayEquals(input, MySwiftLibrary.byteArray(input)); | ||
| } | ||
|
|
||
| @Test | ||
| void byteArray_empty() { | ||
| byte[] input = new byte[] {}; | ||
| assertArrayEquals(input, MySwiftLibrary.byteArray(input)); | ||
| } | ||
|
|
||
| @Test | ||
| void byteArray_null() { | ||
| assertThrows(NullPointerException.class, () -> MySwiftLibrary.byteArray(null)); | ||
| } | ||
|
|
||
| @Test | ||
| void byteArrayExplicit() { | ||
| byte[] input = new byte[] { 10, 20, 30, 40 }; | ||
| assertArrayEquals(input, MySwiftLibrary.byteArrayExplicit(input)); | ||
| } | ||
|
|
||
| @Test | ||
| void charArray() { | ||
| char[] input = new char[] { 10, 20, 30, 40 }; | ||
| assertArrayEquals(input, MySwiftLibrary.charArray(input)); | ||
| } | ||
|
|
||
| @Test | ||
| void shortArray() { | ||
| short[] input = new short[] { 10, 20, 30, 40 }; | ||
| assertArrayEquals(input, MySwiftLibrary.shortArray(input)); | ||
| } | ||
|
|
||
| @Test | ||
| void intArray() { | ||
| int[] input = new int[] { 10, 20, 30, 40 }; | ||
| assertArrayEquals(input, MySwiftLibrary.intArray(input)); | ||
| } | ||
|
|
||
| @Test | ||
| void longArray() { | ||
| long[] input = new long[] { 10, 20, 30, 40 }; | ||
| assertArrayEquals(input, MySwiftLibrary.longArray(input)); | ||
| } | ||
|
|
||
| @Test | ||
| void stringArray() { | ||
| String[] input = new String[] { "hey", "there", "my", "friend" }; | ||
| assertArrayEquals(input, MySwiftLibrary.stringArray(input)); | ||
| } | ||
|
|
||
| @Test | ||
| void floatArray() { | ||
| float[] input = new float[] { 10, 20, 30, 40 }; | ||
| assertArrayEquals(input, MySwiftLibrary.floatArray(input)); | ||
| } | ||
|
|
||
| @Test | ||
| void doubleArray() { | ||
| double[] input = new double[] { 10, 20, 30, 40 }; | ||
| assertArrayEquals(input, MySwiftLibrary.doubleArray(input)); | ||
| } | ||
|
|
||
| @Test | ||
| void objectArray() { | ||
| try (var arena = SwiftArena.ofConfined()) { | ||
| MySwiftClass[] input = new MySwiftClass[]{MySwiftClass.init(arena), MySwiftClass.init(arena), MySwiftClass.init(arena) }; | ||
| assertEquals(3, MySwiftLibrary.objectArray(input, arena).length); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.