Skip to content

Commit 816dab0

Browse files
committed
Rename @JavaImplements to @JavaImplementation to actually match SE-0436
1 parent e5c5753 commit 816dab0

File tree

8 files changed

+18
-23
lines changed

8 files changed

+18
-23
lines changed

Samples/JavaKitSampleApp/Sources/JavaKitExample/JavaKitExample.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ enum SwiftWrappedError: Error {
1818
case message(String)
1919
}
2020

21-
@JavaImplements("com.example.swift.HelloSwift")
21+
@JavaImplementation("com.example.swift.HelloSwift")
2222
extension HelloSwift: HelloSwiftNativeMethods {
2323
@JavaMethod
2424
func sayHello(_ i: Int32, _ j: Int32) -> Int32 {

Sources/JavaKit/Macros.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public macro JavaStaticMethod() = #externalMacro(module: "JavaKitMacros", type:
156156
/// the method can be implemented in Swift with the following:
157157
///
158158
/// ```swift
159-
/// @JavaImplements
159+
/// @JavaImplementation
160160
/// extension Hello {
161161
/// @JavaMethod
162162
/// func sayHello(i: Int32, _ j: Int32) -> Int32 {
@@ -165,4 +165,4 @@ public macro JavaStaticMethod() = #externalMacro(module: "JavaKitMacros", type:
165165
/// }
166166
/// ```
167167
@attached(peer)
168-
public macro JavaImplements(_ fullClassName: String) = #externalMacro(module: "JavaKitMacros", type: "JavaImplementsMacro")
168+
public macro JavaImplementation(_ fullClassName: String) = #externalMacro(module: "JavaKitMacros", type: "JavaImplementationMacro")

Sources/JavaKitMacros/GenerationMode.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ enum GenerationMode {
2626

2727
/// This macro is describing an extension that is implementing the native
2828
/// methods of a Java class.
29-
case JavaImplements
29+
case javaImplementation
3030

3131
/// Determine the mode for Java class generation based on an attribute.
3232
init?(attribute: AttributeSyntax) {
@@ -37,8 +37,8 @@ enum GenerationMode {
3737
case "ExportToJavaClass":
3838
self = .exportToJava
3939

40-
case "JavaImplements":
41-
self = .JavaImplements
40+
case "JavaImplementation":
41+
self = .javaImplementation
4242

4343
default:
4444
return nil

Sources/JavaKitMacros/ImplementsJavaMacro.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ import SwiftSyntax
1616
import SwiftSyntaxBuilder
1717
import SwiftSyntaxMacros
1818

19-
enum JavaImplementsMacro {}
19+
enum JavaImplementationMacro {}
2020

21-
extension JavaImplementsMacro: PeerMacro {
21+
extension JavaImplementationMacro: PeerMacro {
2222
static func expansion(
2323
of node: AttributeSyntax,
2424
providingPeersOf declaration: some DeclSyntaxProtocol,
2525
in context: some MacroExpansionContext
2626
) throws -> [DeclSyntax] {
2727
guard let extensionDecl = declaration.as(ExtensionDeclSyntax.self) else {
28-
throw MacroErrors.JavaImplementsRequiresExtension
28+
throw MacroErrors.javaImplementationRequiresExtension
2929
}
3030

3131
// Dig out the Java class name.

Sources/JavaKitMacros/JavaMethodMacro.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extension JavaMethodMacro: BodyMacro {
3434
// MacroErrors.macroOutOfContext(node.attributeName.trimmedDescription)
3535

3636
switch mode {
37-
case .JavaImplements, .exportToJava:
37+
case .javaImplementation, .exportToJava:
3838
return declaration.body.map { Array($0.statements) } ?? []
3939

4040
case .importFromJava, nil:

Sources/JavaKitMacros/MacroErrors.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
enum MacroErrors: Error {
1616
case unrecognizedJavaClassMacro(String)
17-
case JavaImplementsRequiresExtension
17+
case javaImplementationRequiresExtension
1818
case classNameNotStringLiteral
1919
case classNameNotFullyQualified(String)
2020
case javaClassNotOnType

Sources/JavaKitMacros/SwiftJNIMacrosPlugin.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import SwiftSyntaxMacros
1818
@main
1919
struct JavaKitMacrosPlugin: CompilerPlugin {
2020
var providingMacros: [Macro.Type] = [
21-
JavaImplementsMacro.self,
21+
JavaImplementationMacro.self,
2222
JavaClassMacro.self,
2323
JavaFieldMacro.self,
2424
JavaMethodMacro.self,

USER_GUIDE.md

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ if let url = myObject.as(URL.self) {
235235
236236
### Implementing Java `native` methods in Swift
237237

238-
JavaKit supports implementing Java `native` methods in Swift using JNI with the `@JavaImplements` macro. In Java, the method must be declared as `native`, e.g.,
238+
JavaKit supports implementing Java `native` methods in Swift using JNI with the `@JavaImplementation` macro. In Java, the method must be declared as `native`, e.g.,
239239

240240
```java
241241
package org.swift.javakit.example;
@@ -259,10 +259,10 @@ On the Swift side, the Java class needs to be exposed to Swift through `Java2Swi
259259
}
260260
```
261261

262-
Implementations of `native` methods are written in an extension of the Swift type that has been marked with `@JavaImplements`. The methods themselves must be marked with `@JavaMethod`, indicating that they are available to Java as well. To help ensure that the Swift code implements all of the `native` methods with the right signatures, JavaKit produces a protocol with the Swift type name suffixed by `NativeMethods`. Declare conformance to that protocol and implement its requirements, for example:
262+
Implementations of `native` methods are written in an extension of the Swift type that has been marked with `@JavaImplementation`. The methods themselves must be marked with `@JavaMethod`, indicating that they are available to Java as well. To help ensure that the Swift code implements all of the `native` methods with the right signatures, JavaKit produces a protocol with the Swift type name suffixed by `NativeMethods`. Declare conformance to that protocol and implement its requirements, for example:
263263

264264
```swift
265-
@JavaImplements("org.swift.javakit.HelloSwift")
265+
@JavaImplementation("org.swift.javakit.HelloSwift")
266266
extension Hello: HelloNativeMethods {
267267
@JavaMethod
268268
func reportStatistics(_ meaning: String, _ numbers: [Double]) -> String {
@@ -532,15 +532,10 @@ Now, in the `HelloSwift` Swift library, define a `struct` that provides the `mai
532532
```swift
533533
import JavaKit
534534

535-
@JavaImplements("org.swift.javakit.HelloSwiftMain")
535+
@JavaImplementation("org.swift.javakit.HelloSwiftMain")
536536
struct HelloSwiftMain {
537-
<<<<<<< HEAD
538-
@JavaImplements
539-
static func main(arguments: [String], environment: JNIEnvironment? = nil) {
540-
=======
541537
@JavaStaticMethod
542-
static func main(arguments: [String], environment: JNIEnvironment) {
543-
>>>>>>> 148e53c (JavaKit: Rework `@JavaImplements` to be more like `@implements` language feature)
538+
static func main(arguments: [String], environment: JNIEnvironment? = nil) {
544539
print("Command line arguments are: \(arguments)")
545540
}
546541
}
@@ -571,7 +566,7 @@ struct HelloSwiftMain: ParsableCommand {
571566
@Option(name: .shortAndLong, help: "Enable verbose output")
572567
var verbose: Bool = false
573568

574-
@JavaImplements
569+
@JavaImplementation
575570
static func main(arguments: [String], environment: JNIEnvironment? = nil) {
576571
let command = Self.parseOrExit(arguments)
577572
command.run(environment: environment)

0 commit comments

Comments
 (0)