0001    //
0002    //  OffsetMap.swift
0003    //  SourceKitten
0004    //
0005    //  Created by JP Simard on 2015-01-05.
0006    //  Copyright (c) 2015 SourceKitten. All rights reserved.
0007    //
0008    
0009    /// Type that maps potentially documented declaration offsets to its closest parent offset.
0010    public typealias OffsetMap
OffsetMap.swift:26
    public func generateOffsetMap(documentedTokenOffsets: [Int], dictionary: [String: SourceKitRepresentable]) -> OffsetMap {
OffsetMap.swift:27
        var offsetMap = OffsetMap()
OffsetMap.swift:49
    private func mapOffsets(dictionary: [String: SourceKitRepresentable], offsetMap: OffsetMap) -> OffsetMap {
OffsetMap.swift:49
    private func mapOffsets(dictionary: [String: SourceKitRepresentable], offsetMap: OffsetMap) -> OffsetMap {
= [Int: Int] 0011 0012 /// File methods to generate and manipulate OffsetMap's. 0013 extension File { 0014 /** 0015 Creates an OffsetMap containing offset locations at which there are declarations that likely 0016 have documentation comments, but haven't been documented by SourceKitten yet. 0017 0018 - parameter documentedTokenOffsets: Offsets where there are declarations that likely 0019 have documentation comments. 0020 - parameter dictionary: Docs dictionary to check for which offsets are already 0021 documented. 0022 0023 - returns: OffsetMap containing offset locations at which there are declarations that likely 0024 have documentation comments, but haven't been documented by SourceKitten yet. 0025 */ 0026 public func generateOffsetMap
File.swift:170
        let offsetMap = generateOffsetMap(documentedTokenOffsets, dictionary: dictionary)
(documentedTokenOffsets: [Int], dictionary: [String: SourceKitRepresentable]) -> OffsetMap { 0027 var offsetMap = OffsetMap() 0028 for offset in documentedTokenOffsets { 0029 offsetMap[offset] = 0 0030 } 0031 offsetMap = mapOffsets(dictionary, offsetMap: offsetMap) 0032 let alreadyDocumentedOffsets = offsetMap.filter({ $0.0 == $0.1 }).map { $0.0 } 0033 for alreadyDocumentedOffset in alreadyDocumentedOffsets { 0034 offsetMap.removeValueForKey(alreadyDocumentedOffset) 0035 } 0036 return offsetMap 0037 } 0038 0039 /** 0040 Creates a new OffsetMap that matches all offsets in the offsetMap parameter's keys to its 0041 nearest, currently documented parent offset. 0042 0043 - parameter dictionary: Already documented dictionary. 0044 - parameter offsetMap: Dictionary mapping potentially documented offsets to its nearest parent 0045 offset. 0046 0047 - returns: OffsetMap of potentially documented declaration offsets to its nearest parent offset. 0048 */ 0049 private func mapOffsets
OffsetMap.swift:31
        offsetMap = mapOffsets(dictionary, offsetMap: offsetMap)
OffsetMap.swift:68
                offsetMap = mapOffsets(subDict as! [String: SourceKitRepresentable], offsetMap: offsetMap)
(dictionary: [String: SourceKitRepresentable], offsetMap: OffsetMap) -> OffsetMap { 0050 var offsetMap = offsetMap 0051 // Only map if we're in the correct file 0052 if let rangeStart = SwiftDocKey.getNameOffset(dictionary), 0053 rangeLength = SwiftDocKey.getNameLength(dictionary) where 0054 shouldTreatAsSameFile(dictionary) { 0055 let bodyLength = SwiftDocKey.getBodyLength(dictionary) ?? 0 0056 let rangeMax = Int(rangeStart + rangeLength + bodyLength) 0057 let rangeStart = Int(rangeStart) 0058 let offsetsInRange = offsetMap.keys.filter { 0059 $0 >= rangeStart && $0 <= rangeMax 0060 } 0061 for offset in offsetsInRange { 0062 offsetMap[offset] = rangeStart 0063 } 0064 } 0065 // Recurse! 0066 if let substructure = SwiftDocKey.getSubstructure(dictionary) { 0067 for subDict in substructure { 0068 offsetMap = mapOffsets(subDict as! [String: SourceKitRepresentable], offsetMap: offsetMap) 0069 } 0070 } 0071 return offsetMap 0072 } 0073 } 0074