Skip to content

Commit 82749b1

Browse files
authored
Merge pull request #4 from DougGregor/jextract-nominal-type-resolution
2 parents 973b378 + f32ea31 commit 82749b1

File tree

8 files changed

+575
-69
lines changed

8 files changed

+575
-69
lines changed

Sources/JExtractSwift/ImportedDecls.swift

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,28 @@ public struct ImportedProtocol: ImportedDecl {
2525
public var identifier: String
2626
}
2727

28-
public struct ImportedClass: ImportedDecl {
28+
/// Describes a Swift nominal type (e.g., a class, struct, enum) that has been
29+
/// imported and is being translated into Java.
30+
public struct ImportedNominalType: ImportedDecl {
2931
public var name: ImportedTypeName
30-
31-
public var implementedInterfaces: Set<ImportedTypeName> = []
32+
public var kind: NominalTypeKind
3233

3334
public var initializers: [ImportedFunc] = []
3435
public var methods: [ImportedFunc] = []
3536

36-
public init(name: ImportedTypeName) {
37+
public init(name: ImportedTypeName, kind: NominalTypeKind) {
3738
self.name = name
39+
self.kind = kind
3840
}
3941
}
4042

43+
public enum NominalTypeKind {
44+
case `actor`
45+
case `class`
46+
case `enum`
47+
case `struct`
48+
}
49+
4150
public struct ImportedParam: Hashable {
4251
let param: FunctionParameterSyntax
4352

@@ -99,9 +108,10 @@ public struct ImportedTypeName: Hashable {
99108
javaType.className
100109
}
101110

102-
public init(swiftTypeName: String, javaType: JavaType) {
111+
public init(swiftTypeName: String, javaType: JavaType, swiftMangledName: String? = nil) {
103112
self.swiftTypeName = swiftTypeName
104113
self.javaType = javaType
114+
self.swiftMangledName = swiftMangledName ?? ""
105115
}
106116
}
107117

@@ -126,6 +136,8 @@ public struct ImportedFunc: ImportedDecl, CustomStringConvertible {
126136
/// This is a full name such as init(cap:name:).
127137
public var identifier: String
128138

139+
/// This is the base identifier for the function, e.g., "init" for an
140+
/// initializer or "f" for "f(a:b:)".
129141
public var baseIdentifier: String {
130142
guard let idx = identifier.firstIndex(of: "(") else {
131143
return identifier
@@ -134,7 +146,7 @@ public struct ImportedFunc: ImportedDecl, CustomStringConvertible {
134146
}
135147

136148
/// A display name to use to refer to the Swift declaration with its
137-
/// enclosing type.
149+
/// enclosing type, if there is one.
138150
public var displayName: String {
139151
if let parentName {
140152
return "\(parentName.swiftTypeName).\(identifier)"

0 commit comments

Comments
 (0)