0001    //
0002    //  JSONOutput.swift
0003    //  SourceKitten
0004    //
0005    //  Created by Thomas Goyne on 9/17/15.
0006    //  Copyright © 2015 SourceKitten. All rights reserved.
0007    //
0008    
0009    import Foundation
0010    
0011    /**
0012     JSON Object to JSON String.
0013    
0014     - parameter object: Object to convert to JSON.
0015    
0016     - returns: JSON string representation of the input object.
0017     */
0018    public func toJSON
CodeCompletionItem.swift:47
        return toJSON(dictionaryValue)
JSONOutput.swift:61
    return toJSON(decl.map({ [$0: toOutputDictionary($1)] }).sort({ $0.keys.first < $1.keys.first }))
Structure.swift:41
    public var description: String { return toJSON(toAnyObject(dictionary)) }
SwiftDocs.swift:74
        return toJSON(toAnyObject([file.path ?? "<No File>": docsDictionary]))
SyntaxToken.swift:57
    public var description: String { return toJSON(dictionaryValue) }
(object: AnyObject) -> String { 0019 do { 0020 let prettyJSONData = try NSJSONSerialization.dataWithJSONObject(object, options: .PrettyPrinted) 0021 if let jsonString = NSString(data: prettyJSONData, encoding: NSUTF8StringEncoding) as? String { 0022 return jsonString 0023 } 0024 } catch {} 0025 return "" 0026 } 0027 0028 /** 0029 Convert [String: SourceKitRepresentable] to `[String: AnyObject]`. 0030 0031 - parameter dictionary: [String: SourceKitRepresentable] to convert. 0032 0033 - returns: JSON-serializable Dictionary. 0034 */ 0035 public func toAnyObject
JSONOutput.swift:42
            anyDictionary[key] = object.map { toAnyObject($0 as! [String: SourceKitRepresentable]) }
JSONOutput.swift:44
            anyDictionary[key] = object.map { toAnyObject($0) }
JSONOutput.swift:46
            anyDictionary[key] = toAnyObject(object)
Structure.swift:41
    public var description: String { return toJSON(toAnyObject(dictionary)) }
SwiftDocs.swift:74
        return toJSON(toAnyObject([file.path ?? "<No File>": docsDictionary]))
(dictionary: [String: SourceKitRepresentable]) -> [String: AnyObject] { 0036 var anyDictionary = [String: AnyObject]() 0037 for (key, object) in dictionary { 0038 switch object { 0039 case let object as AnyObject: 0040 anyDictionary[key] = object 0041 case let object as [SourceKitRepresentable]: 0042 anyDictionary[key] = object.map { toAnyObject($0 as! [String: SourceKitRepresentable]) } 0043 case let object as [[String: SourceKitRepresentable]]: 0044 anyDictionary[key] = object.map { toAnyObject($0) } 0045 case let object as [String: SourceKitRepresentable]: 0046 anyDictionary[key] = toAnyObject(object) 0047 case let object as String: 0048 anyDictionary[key] = object 0049 case let object as Int64: 0050 anyDictionary[key] = NSNumber(longLong: object) 0051 case let object as Bool: 0052 anyDictionary[key] = NSNumber(bool: object) 0053 default: 0054 fatalError("Should never happen because we've checked all SourceKitRepresentable types") 0055 } 0056 } 0057 return anyDictionary 0058 } 0059 0060 public func declarationsToJSON
ClangTranslationUnit.swift:95
        return declarationsToJSON(declarations)
(decl: [String: [SourceDeclaration]]) -> String { 0061 return toJSON(decl.map({ [$0: toOutputDictionary($1)] }).sort({ $0.keys.first < $1.keys.first })) 0062 } 0063 0064 private func toOutputDictionary
JSONOutput.swift:91
    setA(.Substructure, decl.children.map(toOutputDictionary))
JSONOutput.swift:101
    return ["key.substructure": decl.map(toOutputDictionary), "key.diagnostic_stage": ""]
(decl: SourceDeclaration) -> [String: AnyObject] { 0065 var dict = [String: AnyObject]() 0066 func set(key: SwiftDocKey, _ value: AnyObject?) { 0067 if let value = value { 0068 dict[key.rawValue] = value 0069 } 0070 } 0071 func setA(key: SwiftDocKey, _ value: [AnyObject]?) { 0072 if let value = value where value.count > 0 { 0073 dict[key.rawValue] = value 0074 } 0075 } 0076 0077 set(.Kind, decl.type.rawValue) 0078 set(.FilePath, decl.location.file) 0079 set(.DocFile, decl.location.file) 0080 set(.DocLine, Int(decl.location.line)) 0081 set(.DocColumn, Int(decl.location.column)) 0082 set(.Name, decl.name) 0083 set(.USR, decl.usr) 0084 set(.ParsedDeclaration, decl.declaration) 0085 set(.DocumentationComment, decl.commentBody) 0086 set(.ParsedScopeStart, Int(decl.extent.start.line)) 0087 set(.ParsedScopeEnd, Int(decl.extent.end.line)) 0088 0089 setA(.DocResultDiscussion, decl.documentation?.returnDiscussion.map(toOutputDictionary)) 0090 setA(.DocParameters, decl.documentation?.parameters.map(toOutputDictionary)) 0091 setA(.Substructure, decl.children.map(toOutputDictionary)) 0092 0093 if decl.commentBody != nil { 0094 set(.FullXMLDocs, "") 0095 } 0096 0097 return dict 0098 } 0099 0100 private func toOutputDictionary
JSONOutput.swift:61
    return toJSON(decl.map({ [$0: toOutputDictionary($1)] }).sort({ $0.keys.first < $1.keys.first }))
(decl: [SourceDeclaration]) -> [String: AnyObject] { 0101 return ["key.substructure": decl.map(toOutputDictionary), "key.diagnostic_stage": ""] 0102 } 0103 0104 private func toOutputDictionary
JSONOutput.swift:90
    setA(.DocParameters, decl.documentation?.parameters.map(toOutputDictionary))
(param: Parameter) -> [String: AnyObject] { 0105 return ["name": param.name, "discussion": param.discussion.map(toOutputDictionary)] 0106 } 0107 0108 private func toOutputDictionary
JSONOutput.swift:89
    setA(.DocResultDiscussion, decl.documentation?.returnDiscussion.map(toOutputDictionary))
JSONOutput.swift:105
    return ["name": param.name, "discussion": param.discussion.map(toOutputDictionary)]
(text: Text) -> [String: AnyObject] { 0109 switch text { 0110 case .Para(let str, let kind): 0111 return ["kind": kind ?? "", "Para": str] 0112 case .Verbatim(let str): 0113 return ["kind": "", "Verbatim": str] 0114 } 0115 } 0116