Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
24 changes: 18 additions & 6 deletions Sources/JExtractSwift/ImportedDecls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,28 @@ public struct ImportedProtocol: ImportedDecl {
public var identifier: String
}

public struct ImportedClass: ImportedDecl {
/// Describes a Swift nominal type (e.g., a class, struct, enum) that has been
/// imported and is being translated into Java.
public struct ImportedNominalType: ImportedDecl {
public var name: ImportedTypeName

public var implementedInterfaces: Set<ImportedTypeName> = []
public var kind: NominalTypeKind

public var initializers: [ImportedFunc] = []
public var methods: [ImportedFunc] = []

public init(name: ImportedTypeName) {
public init(name: ImportedTypeName, kind: NominalTypeKind) {
self.name = name
self.kind = kind
}
}

public enum NominalTypeKind {
case `actor`
case `class`
case `enum`
case `struct`
}

public struct ImportedParam: Hashable {
let param: FunctionParameterSyntax

Expand Down Expand Up @@ -99,9 +108,10 @@ public struct ImportedTypeName: Hashable {
javaType.className
}

public init(swiftTypeName: String, javaType: JavaType) {
public init(swiftTypeName: String, javaType: JavaType, swiftMangledName: String? = nil) {
self.swiftTypeName = swiftTypeName
self.javaType = javaType
self.swiftMangledName = swiftMangledName ?? ""
}
}

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

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

/// A display name to use to refer to the Swift declaration with its
/// enclosing type.
/// enclosing type, if there is one.
public var displayName: String {
if let parentName {
return "\(parentName.swiftTypeName).\(identifier)"
Expand Down
Loading