glato / emerge

Emerge is a browser-based interactive codebase and dependency visualization tool for many different programming languages. It supports some basic code quality and graph metrics and provides a simple and intuitive way to explore and analyze a codebase by using graph structures.
MIT License
783 stars 46 forks source link

Add support for swift `protocol`, `enum`, `let` #13

Closed Andrea-Scuderi closed 2 years ago

Andrea-Scuderi commented 2 years ago

Improve Swift language support

Test Source code:

import Foundation

protocol Naming {
    var name: String { get set }
}

protocol Describing {
    var describing: String { get }
}

class ClassA: Naming & Describing {

    static let shared = ClassA()

    var name: String = "A"
    let id: UUID = UUID()
    var describing: String = "Class A"
}

class ClassB: ClassA {
    func show() {
        print(name)
    }
}

enum EnumA {
    case one
    case two(EnumB)
}

enum EnumB: String, Describing {
    case one
    case two

    var describing: String {
        self.rawValue
    }
}

struct StructC<T: Naming>: Describing {
    var name: String = "C"
    let state: EnumA = .one
    var generic: T

    var describing: String = "Class C"

    init(generic: T) {
        self.generic = generic
    }
}

public struct EmergeSwiftTest {
    public private(set) var text = "Hello, World!"

    var b = ClassB()
    let eB: EnumB = .one
    let eA = EnumA.two(.one)

    func show() {
        b.show()
        print(ClassA.shared.name)
    }
}

Output:

Screenshot 2022-01-16 at 13 42 39

Desired output:

Note: ** Static entities are not evaluated

glato commented 2 years ago

@Andrea-Scuderi Seems to be working fine, thanks for the enhancement. While I was testing your PR, I've found some nasty bugs in the SwiftParser when creating an additional entity inheritance graph. I will check this in more detail in the coming days to also allow your additional keywords (e.g. enum, protocol) to be included correctly in the inheritance graph.