yoshimkd / swift-auto-diagram

A Ruby script that scans all swift code from the specified folders and files and automatically generates an entity diagram (similar to a class diagram) which can be viewed in a browser.
MIT License
496 stars 57 forks source link

Single protocol conformance on a class assumed to be inheritance #2

Open maddiemort opened 7 years ago

maddiemort commented 7 years ago

A class that conforms to a single protocol only and does not inherit is assumed to inherit from the protocol, which is assumed to be a class.

For example:

class Day: Comparable {
    // ...
}

produces this:

screen shot 2017-02-25 at 14 01 00

Whereas it should say "conforms to" and "protocol Comparable"

yoshimkd commented 7 years ago

@sorenmortensen

The script that generates the diagram analyses the code as a text only. When your class conforms to a protocol that is not being analyzed by the script (like Comparable), there's no way for the script to know the type that goes after the ":" part in the class definition. To satisfy most of the use cases, the script treats the first type after the ":" as a super class, or as a protocol only if it's part of the analysis process.

I don't see any way how this can be fixed with the approach to analyze the code as a text. Maybe these kinds of issues can be solved by changing the approach to analyze a compiler output but that would be a whole other project.

If you have any other idea or would want to make a pull request about this, go ahead and let me know, otherwise I'd be closing the issue.

Anyway, thanks for noticing our script's pitfalls. :)