Skip to content

Commit 3b87d8f

Browse files
committed
test fixes
1 parent e9cfec1 commit 3b87d8f

File tree

9 files changed

+33
-286
lines changed

9 files changed

+33
-286
lines changed

Samples/SwiftJavaExtractJNISampleApp/LICENSE.txt

Lines changed: 0 additions & 202 deletions
This file was deleted.

Samples/SwiftJavaExtractJNISampleApp/Sources/MySwiftLibrary/NestedTypes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ public enum NestedEnum {
4444
public struct OneStruct {
4545
public init() {}
4646
}
47-
}
47+
}

Sources/JavaStdlib/JavaLangReflect/generated/Executable.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ open class Executable: AccessibleObject {
1111
@JavaMethod
1212
open func getModifiers() -> Int32
1313

14-
// @JavaMethod // FIXME why does this clash with Method.getTypeParameters?
15-
// open func getTypeParameters() -> [TypeVariable<JavaObject>?]
16-
1714
@JavaMethod
1815
open func getParameterTypes() -> [JavaClass<JavaObject>?]
1916

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2024 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+
import CSwiftJavaJNI
16+
17+
extension JavaClass: CustomStringConvertible {
18+
public var description: String {
19+
toString()
20+
}
21+
}

Sources/SwiftJavaToolLib/JavaTranslator.swift

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -147,55 +147,19 @@ extension JavaTranslator {
147147
preferValueTypes: Bool,
148148
outerOptional: OptionalKind
149149
) throws -> String {
150-
151-
// if let method,
152-
// let parameterizedType = javaType.as(ParameterizedType.self) {
153-
// if method.getGenericParameterTypes().contains(where: {$0?.getTypeName() == javaType.getTypeName()}) {
154-
// fatalError("java type = \(javaType.as(ParameterizedType.self))")
155-
// return javaType.getTypeName()
156-
// }
157-
// }
158-
159-
if isGenericJavaType(javaType) {
160-
if let method {
161-
print("[swift] generic method! \(method.getDeclaringClass().getName()).\(method.getName())")
162-
let genericOriginInfos = getGenericJavaTypeOriginInfo(javaType, from: method)
163-
print("genericOriginInfos = \(genericOriginInfos)")
164-
}
165-
}
166-
167150
// Replace type variables with their bounds.
168151
if let typeVariable = javaType.as(TypeVariable<GenericDeclaration>.self),
169152
typeVariable.getBounds().count == 1,
170153
let bound = typeVariable.getBounds()[0]
171154
{
172-
print("[swift] was type var: \(typeVariable)")
173-
print("[swift] was type var: \(typeVariable.toString())")
174-
print("[swift] was type var: \(typeVariable.getClass().getName())")
175-
print("[swift] was type var bound: \(bound)")
176-
// let typeName = try getSwiftTypeNameAsString(
177-
// bound,
178-
// preferValueTypes: preferValueTypes,
179-
// outerOptional: outerOptional
180-
// )
181-
// print("[swift] was type var: \(typeVariable.toString()) ----> \(typeName)")
182155
return outerOptional.adjustTypeName(typeVariable.getName())
183156
}
184157

185-
if let paramType = javaType.as(ParameterizedType.self) {
186-
print("[swift] paramType = \(paramType)")
187-
let typeArgs: [Type?] = paramType.getActualTypeArguments()
188-
for typeArg in typeArgs {
189-
print("Type arg = \(typeArg)")
190-
}
191-
}
192-
193158
// Replace wildcards with their upper bound.
194159
if let wildcardType = javaType.as(WildcardType.self),
195160
wildcardType.getUpperBounds().count == 1,
196161
let bound = wildcardType.getUpperBounds()[0]
197162
{
198-
print("[swift] was wildcard")
199163
// Replace a wildcard type with its first bound.
200164
return try getSwiftTypeNameAsString(
201165
bound,
@@ -206,7 +170,6 @@ extension JavaTranslator {
206170

207171
// Handle array types by recursing into the component type.
208172
if let arrayType = javaType.as(GenericArrayType.self) {
209-
print("[swift] was array")
210173
if preferValueTypes {
211174
let elementType = try getSwiftTypeNameAsString(
212175
arrayType.getGenericComponentType()!,
@@ -264,24 +227,18 @@ extension JavaTranslator {
264227
}
265228
}
266229

267-
print("[swift][swift-java][debug] Convert direct \(javaType)")
268-
269230
// Handle direct references to Java classes.
270231
guard let javaClass = javaType.as(JavaClass<JavaObject>.self) else {
271232
throw TranslationError.unhandledJavaType(javaType)
272233
}
273234

274-
print("[swift][swift-java][debug] Java class \(javaClass) | \(javaClass.toString())")
275-
if isGenericJavaType(javaType) {
276-
print("[swift][swift-java][debug] is generic \(javaClass.toString())")
277-
}
278-
279-
280235
let (swiftName, isOptional) = try getSwiftTypeName(javaClass, preferValueTypes: preferValueTypes)
281-
var resultString = swiftName
282-
if isOptional {
283-
resultString = outerOptional.adjustTypeName(resultString)
284-
}
236+
let resultString =
237+
if isOptional {
238+
outerOptional.adjustTypeName(swiftName)
239+
} else {
240+
swiftName
241+
}
285242
return resultString
286243
}
287244

Tests/JExtractSwiftTests/JNI/JNINestedTypesTests.swift

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
import JExtractSwiftLib
16-
import SwiftJavaConfigurationShared
1716
import Testing
1817

1918
@Suite
2019
struct JNINestedTypesTests {
2120
let source1 = """
22-
"""
2321
public class A {
2422
public class B {
2523
public func g(c: C) {}
@@ -28,14 +26,7 @@ struct JNINestedTypesTests {
2826
public func h(b: B) {}
2927
}
3028
}
31-
"""
32-
3329
}
34-
func test_nested_in_extension() throws {
35-
var config = Configuration()
36-
config.swiftModule = "__FakeModule"
37-
let st = Swift2JavaTranslator(config: config)
38-
st.log.logLevel = .error
3930
4031
public func f(a: A, b: A.B, c: A.B.C) {}
4132
"""
@@ -143,4 +134,4 @@ struct JNINestedTypesTests {
143134
]
144135
)
145136
}
146-
}
137+
}

Tests/SwiftJavaTests/BasicRuntimeTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class BasicRuntimeTests: XCTestCase {
7373
do {
7474
_ = try JavaClass<Nonexistent>(environment: environment)
7575
} catch {
76-
XCTAssertEqual(String(describing: error), "java.lang.NoClassDefFoundError: org/swift/javakit/Nonexistent")
76+
XCTAssertEqual(String(describing: error), "java.lang.NoClassDefFoundError(org/swift/javakit/Nonexistent)")
7777
}
7878
}
7979

0 commit comments

Comments
 (0)