Skip to content

Commit ef76a84

Browse files
committed
revert subprocess
1 parent 0685f55 commit ef76a84

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

Sources/ExampleSwiftLibrary/MySwiftLibrary.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import Glibc
2323
import CRT
2424
#elseif canImport(Darwin)
2525
import Darwin.C
26+
#elseif canImport(Android)
27+
import Android
2628
#endif
2729

2830
public func helloWorld() {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the Swift.org project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of Swift.org project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
public enum AndroidSupport {
16+
/// Performs any known name conversions
17+
/// for types that are desugared on specific Android versions
18+
public static func androidDesugarClassNameConversion(
19+
for fullClassName: String
20+
) -> String {
21+
#if os(Android) && compiler(>=6.3)
22+
switch fullClassName {
23+
case "java.util.Optional":
24+
// On API 23, Optionals are desugared
25+
if #unavailable(Android 24) {
26+
return "j$.util.Optional"
27+
}
28+
29+
default:
30+
break
31+
}
32+
#endif
33+
return fullClassName
34+
}
35+
}

Sources/SwiftJavaMacros/JavaClassMacro.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ extension JavaClassMacro: MemberMacro {
7373
let superclass = specifiedSuperclass ?? "JavaObject"
7474

7575
// Check that the class name is fully-qualified, as it should be.
76-
let className = classNameSegment.content.text
77-
if className.firstIndex(of: ".") == nil {
78-
throw MacroErrors.classNameNotFullyQualified(className)
76+
let specifiedClassName = classNameSegment.content.text
77+
if specifiedClassName.firstIndex(of: ".") == nil {
78+
throw MacroErrors.classNameNotFullyQualified(specifiedClassName)
7979
}
8080

8181
var members: [DeclSyntax] = []
82-
82+
8383
// Determine the modifiers to use for the fullJavaClassName member.
8484
let fullJavaClassNameMemberModifiers: String
8585
switch (isSwiftClass, isJavaLangObject) {
@@ -94,7 +94,13 @@ extension JavaClassMacro: MemberMacro {
9494
let classNameAccessSpecifier = isSwiftClass ? "open" : "public"
9595
members.append("""
9696
/// The full Java class name for this Swift type.
97-
\(raw: classNameAccessSpecifier) \(raw: fullJavaClassNameMemberModifiers) var fullJavaClassName: String { \(literal: className) }
97+
\(raw: classNameAccessSpecifier) \(raw: fullJavaClassNameMemberModifiers) var fullJavaClassName: String {
98+
#if os(Android)
99+
AndroidSupport.androidDesugarClassNameConversion(for: "\(raw: specifiedClassName)")
100+
#else
101+
"\(raw: specifiedClassName)"
102+
#endif
103+
}
98104
"""
99105
)
100106

0 commit comments

Comments
 (0)