A description of this package.
- We analyse both .h / .m for Objective-c this will result in more functions than it actually is.
Its possible to analyse the code both synchronous IO<A>
or asynchronous Deferred<A>
.
Internally both use IO<A>
which is blocking the thread until its done, but it can be started wrapped in a Deferred for a better experience with apps with GUI.
IO<A>
Is totally lazy, it wont execute anything until you call unsafeRun()
and Deferred
will start the analyses when you run it and the result will come as a callback.
All version that returns a Deferred
has a Async(...) postfix in the function signature. Ex:
CodeAnalyser().fileInfoAsync(from: "../somepath", language: [.swift, .kotlin]) -> Deferred<[FileInfo]>
CodeAnalyser().statisticsAsync(from: "../somepath", language: [.swift, .objectiveC]) -> Deferred<([LanguageSummary], [Statistics])>
Getting value out of deferred:
CodeAnalyser()
.fileInfoAsync(from: "../somepath", language: [.swift, .kotlin])
.run { fileinfo in
print(fileinfo)
}
CodeAnalyser().fileInfo(from: "../somepath") -> IO<[FileInfo]>
CodeAnalyser().statistics(from: "../somepath", language: .swift) -> IO<([LanguageSummary], [Statistics])>
let fileinfo = CodeAnalyser()
.fileInfo(from: "../somepath", language: [.swift, .kotlin])
.unsafeRun()
- Path will run recusively. There is two overloads with different results:
- Statistics and summary for all files
([LanguageSummary], [Statistics])
- A list of fileinfo for all files
[FileInfo]
- Statistics and summary for all files
- Analyse a single file
FileInfo
Default language parameter is all, you can specify one or multiple languages you want to analyse. Whats happening under the hood is that all files with matching extension will be analysed.
let (languageSummary: [LanguageSummary], statistics: [Statistics]) = CodeAnalyser()
.statistics(from: "../somepath", language: .swift)
.unsafeRun()
Use this if you want to list all the files in a project and see statistics for each file
let fileInfos: [FileInfo] = CodeAnalyser()
.fileInfo(from: "../somepath")
.unsafeRun()
Synchronous:
func analyseSourcefile(_ filename: String, filedata: String, filetype: Filetype) ->IO<Fileinfo>
Asynchronous:
func analyseSourcefileAsync(_ filename: String, filedata: String, filetype: Filetype) ->Deferred<Fileinfo>
public struct Fileinfo {
public let filename: String
public let classes: Int
public let structs: Int
public let enums: Int
public let interfaces: Int
public let functions: Int
public let imports: Int
public let extensions: Int
public let linecount: Int
public let filetype: Filetype
}
An enum to show wich language (or all/none)
public struct Filetype: OptionSet {
public let rawValue: Int
public static let swift = Filetype(rawValue: 1 << 0)
public static let kotlin = Filetype(rawValue: 1 << 1)
public static let objectiveC = Filetype(rawValue: 1 << 2)
public static let all: Filetype = [.swift, .kotlin, .objectiveC]
public static let empty: Filetype = []
public init (rawValue: Int) {
self.rawValue = rawValue
}
}
Language Summary holds the information about every language. Filetype will tell you which language it is.
public struct LanguageSummary {
public let classes: Int
public let structs: Int
public let enums: Int
public let interfaces: Int
public let functions: Int
public let imports: Int
public let extensions: Int
public let linecount: Int
public let filecount: Int
public let filetype: Filetype
}
Will return the percentage based on linecount. Filetype will tell you which language it is.
public struct Statistics {
public let filetype: Filetype
public let lineCountPercentage: Double
}
- pinfo (CLI) https://github.com/konrad1977/ProjectExplorer