Skip to content

[JExtract] Generate JNI code for classes (static methods and initializers) #298

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 9 commits into from
Jul 3, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

public class MySwiftClass {
let x: Int64
let y: Int64

public static func method() {
p("Hello from static method in a class!")
}

public init(x: Int64, y: Int64) {
self.x = x
self.y = y
p("\(self)")
}

public init() {
self.x = 10
self.y = 5
}

deinit {
p("deinit called!")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ static void examples() {
long i = MySwiftLibrary.globalMakeInt();
SwiftKit.trace("globalMakeInt() = " + i);

MySwiftClass.method();

MySwiftClass myClass = MySwiftClass.init(10, 5);
MySwiftClass myClass2 = MySwiftClass.init();

System.out.println("DONE.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ extension FFMSwift2JavaGenerator {
}
}

extension JavaConversionStep {
extension FFMSwift2JavaGenerator.JavaConversionStep {
/// Whether the conversion uses SwiftArena.
var requiresSwiftArena: Bool {
switch self {
Expand Down
Loading
Loading