Skip to content

Commit

Permalink
Merge pull request #449 from johnfairh/objc-swift-decls
Browse files Browse the repository at this point in the history
Fix generic Swift declaration generation from ObjC
  • Loading branch information
jpsim authored Nov 29, 2017
2 parents c297619 + 459cfb8 commit 5114805
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

##### Bug Fixes

* None.
* Fix Swift declarations when generating Objective-C docs for generic types.
[John Fairhurst](https://github.com/johnfairh)

## 0.18.4

Expand Down
14 changes: 1 addition & 13 deletions Source/SourceKittenFramework/Clang+SourceKitten.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,21 +212,9 @@ extension CXCursor {
return nil
}

// SourceKit with Xcode 9+ doesn't escape ampersands in its XML output, so let's sanitize the XML ourselves.
func fixAmpersandInXML(_ xml: String) -> String {
return xml.replacingOccurrences(of: " & ", with: " & ")
}

let cursorInfo = Request.cursorInfo(file: swiftUUID, offset: usrOffset, arguments: compilerArguments).send()
if let docsXML = cursorInfo[SwiftDocKey.fullXMLDocs.rawValue] as? String,
case let fixedDocsXML = fixAmpersandInXML(docsXML),
let swiftDeclaration = SWXMLHash.parse(fixedDocsXML).children.first?["Declaration"].element?.text {
return swiftDeclaration
}

if let annotatedDeclarationXML = cursorInfo[SwiftDocKey.annotatedDeclaration.rawValue] as? String,
case let fixedAnnotatedDeclarationXML = fixAmpersandInXML(annotatedDeclarationXML),
let swiftDeclaration = SWXMLHash.parse(fixedAnnotatedDeclarationXML).element?.recursiveText {
let swiftDeclaration = SWXMLHash.parse(annotatedDeclarationXML).element?.recursiveText {
return swiftDeclaration
}

Expand Down
10 changes: 5 additions & 5 deletions Tests/SourceKittenFrameworkTests/Fixtures/Realm@swift-3.2.json
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@
"key.usr" : "c:objc(cs)RLMArray(cm)new"
}
],
"key.swift_declaration" : "class RLMArray",
"key.swift_declaration" : "class RLMArray<RLMObjectType> : NSObject, RLMCollection, NSFastEnumeration where RLMObjectType : RLMObject",
"key.unavailable_message" : "",
"key.usr" : "c:objc(cs)RLMArray"
},
Expand Down Expand Up @@ -5487,7 +5487,7 @@
"key.parsed_declaration" : "- (nonnull RLMResults<RLMObjectType> *)objectsWithPredicate:\n (nonnull NSPredicate *)predicate;",
"key.parsed_scope.end" : 132,
"key.parsed_scope.start" : 132,
"key.swift_declaration" : "func objects(with predicate: NSPredicate) -> RLMResults",
"key.swift_declaration" : "func objects(with predicate: NSPredicate) -> RLMResults<RLMObjectType>",
"key.unavailable_message" : "",
"key.usr" : "c:objc(cs)RLMResults(im)objectsWithPredicate:"
},
Expand Down Expand Up @@ -5532,7 +5532,7 @@
"key.parsed_declaration" : "- (nonnull RLMResults<RLMObjectType> *)\nsortedResultsUsingProperty:(nonnull NSString *)property\n ascending:(BOOL)ascending;",
"key.parsed_scope.end" : 142,
"key.parsed_scope.start" : 142,
"key.swift_declaration" : "func sortedResults(usingProperty property: String, ascending: Bool) -> RLMResults",
"key.swift_declaration" : "func sortedResults(usingProperty property: String, ascending: Bool) -> RLMResults<RLMObjectType>",
"key.unavailable_message" : "",
"key.usr" : "c:objc(cs)RLMResults(im)sortedResultsUsingProperty:ascending:"
},
Expand Down Expand Up @@ -5568,7 +5568,7 @@
"key.parsed_declaration" : "- (nonnull RLMResults<RLMObjectType> *)sortedResultsUsingDescriptors:\n (nonnull NSArray *)properties;",
"key.parsed_scope.end" : 151,
"key.parsed_scope.start" : 151,
"key.swift_declaration" : "func sortedResults(usingDescriptors properties: [Any]) -> RLMResults",
"key.swift_declaration" : "func sortedResults(usingDescriptors properties: [Any]) -> RLMResults<RLMObjectType>",
"key.unavailable_message" : "",
"key.usr" : "c:objc(cs)RLMResults(im)sortedResultsUsingDescriptors:"
},
Expand Down Expand Up @@ -5790,7 +5790,7 @@
"key.usr" : "c:objc(cs)RLMResults(cm)new"
}
],
"key.swift_declaration" : "class RLMResults",
"key.swift_declaration" : "class RLMResults<RLMObjectType> : NSObject, RLMCollection, NSFastEnumeration where RLMObjectType : RLMObject",
"key.unavailable_message" : "",
"key.usr" : "c:objc(cs)RLMResults"
}
Expand Down

0 comments on commit 5114805

Please sign in to comment.