Skip to content

Commit

Permalink
Renamed documentation-related symbols to include "Documentation" in t…
Browse files Browse the repository at this point in the history
…heir names.
  • Loading branch information
tristanlabelle committed Oct 30, 2023
1 parent 551eea6 commit 5e013b6
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 50 deletions.
2 changes: 1 addition & 1 deletion Generator/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"location" : "https://github.com/tristanlabelle/swift-dotnetmetadata",
"state" : {
"branch" : "main",
"revision" : "a1cf58af7fdf44776bd63ad502cee56894082288"
"revision" : "b3cffa364adcc0785590f530dab60dfc754fc714"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public struct SwiftDocComment {
public struct SwiftDocumentationComment {
public var summary: [Block]?
public var parameters = [Param]()
public var returns: [Span]?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@

extension SwiftSyntaxWriter {
internal func writeDocComment(_ docComment: SwiftDocComment) {
internal func writeDocumentationComment(_ documentationComment: SwiftDocumentationComment) {
output.writeLine("/**")
if let summary = docComment.summary {
if let summary = documentationComment.summary {
for block in summary { writeDocCommentBlock(block) }
}

for param in docComment.parameters {
for param in documentationComment.parameters {
output.write("- Parameter ")
output.write(param.name)
output.write(": ")
output.write(param.description)
output.endLine()
}

if let returns = docComment.returns {
if let returns = documentationComment.returns {
output.write("- Returns: ")
for span in returns { writeDocCommentSpan(span) }
output.endLine()
Expand All @@ -23,7 +23,7 @@ extension SwiftSyntaxWriter {
output.writeLine("*/")
}

fileprivate func writeDocCommentBlock(_ block: SwiftDocComment.Block) {
fileprivate func writeDocCommentBlock(_ block: SwiftDocumentationComment.Block) {
switch block {
case .paragraph(let spans):
for span in spans { writeDocCommentSpan(span) }
Expand All @@ -33,7 +33,7 @@ extension SwiftSyntaxWriter {
}
}

fileprivate func writeDocCommentSpan(_ span: SwiftDocComment.Span) {
fileprivate func writeDocCommentSpan(_ span: SwiftDocumentationComment.Span) {
switch span {
case .text(let string): output.write(string)
default:
Expand Down
20 changes: 10 additions & 10 deletions Generator/Sources/CodeWriters/Swift/SyntaxWriters/Members.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extension SwiftDeclarationWriter {
public func writeStoredProperty(
docComments: SwiftDocComment? = nil,
documentation: SwiftDocumentationComment? = nil,
visibility: SwiftVisibility = .implicit,
setVisibility: SwiftVisibility = .implicit,
static: Bool = false,
Expand All @@ -14,7 +14,7 @@ extension SwiftDeclarationWriter {
precondition(initialValue == nil || initializer == nil)

var output = output
if let docComments { writeDocComment(docComments) }
if let documentation { writeDocumentationComment(documentation) }
output.beginLine(grouping: .withName("storedProperty"))
visibility.write(to: &output, trailingSpace: true)
if setVisibility != .implicit {
Expand All @@ -41,7 +41,7 @@ extension SwiftDeclarationWriter {
}

public func writeComputedProperty(
docComments: SwiftDocComment? = nil,
documentation: SwiftDocumentationComment? = nil,
visibility: SwiftVisibility = .implicit,
static: Bool = false,
override: Bool = false,
Expand All @@ -54,7 +54,7 @@ extension SwiftDeclarationWriter {
precondition(set == nil || !`throws`)

var output = output
if let docComments { writeDocComment(docComments) }
if let documentation { writeDocumentationComment(documentation) }
output.beginLine(grouping: .never)
visibility.write(to: &output, trailingSpace: true)
if `static` { output.write("static ") }
Expand Down Expand Up @@ -88,7 +88,7 @@ extension SwiftDeclarationWriter {
}

public func writeFunc(
docComments: SwiftDocComment? = nil,
documentation: SwiftDocumentationComment? = nil,
visibility: SwiftVisibility = .implicit,
static: Bool = false,
override: Bool = false,
Expand All @@ -99,7 +99,7 @@ extension SwiftDeclarationWriter {
returnType: SwiftType? = nil,
body: (inout SwiftStatementWriter) throws -> Void) rethrows {

if let docComments { writeDocComment(docComments) }
if let documentation { writeDocumentationComment(documentation) }
output.beginLine(grouping: .never)
writeFuncHeader(
visibility: visibility,
Expand All @@ -117,12 +117,12 @@ extension SwiftDeclarationWriter {
}

public func writeEnumCase(
docComments: SwiftDocComment? = nil,
documentation: SwiftDocumentationComment? = nil,
name: String,
rawValue: String? = nil) {

var output = output
if let docComments { writeDocComment(docComments) }
if let documentation { writeDocumentationComment(documentation) }
output.beginLine(grouping: .withName("case"))
output.write("case ")
SwiftIdentifier.write(name, to: &output)
Expand All @@ -136,7 +136,7 @@ extension SwiftDeclarationWriter {
}

public func writeInit(
docComments: SwiftDocComment? = nil,
documentation: SwiftDocumentationComment? = nil,
visibility: SwiftVisibility = .implicit,
required: Bool = false,
convenience: Bool = false,
Expand All @@ -147,7 +147,7 @@ extension SwiftDeclarationWriter {
body: (inout SwiftStatementWriter) throws -> Void) rethrows {

var output = output
if let docComments { writeDocComment(docComments) }
if let documentation { writeDocumentationComment(documentation) }
output.beginLine(grouping: .never)
visibility.write(to: &output, trailingSpace: true)
if `required` { output.write("required ") }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extension SwiftSourceFileWriter {
public func writeProtocol(
docComments: SwiftDocComment? = nil,
documentation: SwiftDocumentationComment? = nil,
visibility: SwiftVisibility = .implicit,
name: String,
typeParameters: [String] = [],
Expand All @@ -9,7 +9,7 @@ extension SwiftSourceFileWriter {
members: (SwiftProtocolBodyWriter) throws -> Void) rethrows {

var output = output
if let docComments = docComments { writeDocComment(docComments) }
if let documentation = documentation { writeDocumentationComment(documentation) }
output.beginLine(grouping: .never)
visibility.write(to: &output, trailingSpace: true)
output.write("protocol ")
Expand Down Expand Up @@ -38,7 +38,7 @@ public struct SwiftProtocolBodyWriter: SwiftSyntaxWriter {
}

public func writeProperty(
docComments: SwiftDocComment? = nil,
documentation: SwiftDocumentationComment? = nil,
static: Bool = false,
name: String,
type: SwiftType,
Expand All @@ -48,7 +48,7 @@ public struct SwiftProtocolBodyWriter: SwiftSyntaxWriter {
precondition(!set || !`throws`)

var output = output
if let docComments { writeDocComment(docComments) }
if let documentation { writeDocumentationComment(documentation) }
output.beginLine(grouping: .withName("protocolProperty"))
if `static` { output.write("static ") }
output.write("var ")
Expand All @@ -62,7 +62,7 @@ public struct SwiftProtocolBodyWriter: SwiftSyntaxWriter {
}

public func writeFunc(
docComments: SwiftDocComment? = nil,
documentation: SwiftDocumentationComment? = nil,
isPropertySetter: Bool = false,
static: Bool = false,
name: String,
Expand All @@ -71,7 +71,7 @@ public struct SwiftProtocolBodyWriter: SwiftSyntaxWriter {
throws: Bool = false,
returnType: SwiftType? = nil) {

if let docComments { writeDocComment(docComments) }
if let documentation { writeDocumentationComment(documentation) }
output.beginLine(grouping: .withName(isPropertySetter ? "protocolProperty" : "protocolFunc"))
writeFuncHeader(
visibility: .implicit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public struct SwiftTypeDefinitionWriter: SwiftDeclarationWriter {

extension SwiftDeclarationWriter {
public func writeClass(
docComments: SwiftDocComment? = nil,
documentation: SwiftDocumentationComment? = nil,
visibility: SwiftVisibility = .implicit,
final: Bool = false,
name: String,
Expand All @@ -14,7 +14,7 @@ extension SwiftDeclarationWriter {
definition: (SwiftTypeDefinitionWriter) throws -> Void) rethrows {

var output = output
if let docComments { writeDocComment(docComments) }
if let documentation { writeDocumentationComment(documentation) }
output.beginLine(grouping: .never)
visibility.write(to: &output, trailingSpace: true)
if final { output.write("final ") }
Expand All @@ -28,15 +28,15 @@ extension SwiftDeclarationWriter {
}

public func writeStruct(
docComments: SwiftDocComment? = nil,
documentation: SwiftDocumentationComment? = nil,
visibility: SwiftVisibility = .implicit,
name: String,
typeParameters: [String] = [],
protocolConformances: [SwiftType] = [],
definition: (SwiftTypeDefinitionWriter) throws -> Void) rethrows {

var output = output
if let docComments { writeDocComment(docComments) }
if let documentation { writeDocumentationComment(documentation) }
output.beginLine(grouping: .never)
visibility.write(to: &output, trailingSpace: true)
output.write("struct ")
Expand All @@ -49,7 +49,7 @@ extension SwiftDeclarationWriter {
}

public func writeEnum(
docComments: SwiftDocComment? = nil,
documentation: SwiftDocumentationComment? = nil,
visibility: SwiftVisibility = .implicit,
name: String,
typeParameters: [String] = [],
Expand All @@ -58,7 +58,7 @@ extension SwiftDeclarationWriter {
definition: (SwiftTypeDefinitionWriter) throws -> Void) rethrows {

var output = output
if let docComments { writeDocComment(docComments) }
if let documentation { writeDocumentationComment(documentation) }
output.beginLine(grouping: .never)
visibility.write(to: &output, trailingSpace: true)
output.write("enum ")
Expand All @@ -71,14 +71,14 @@ extension SwiftDeclarationWriter {
}

public func writeTypeAlias(
docComments: SwiftDocComment? = nil,
documentation: SwiftDocumentationComment? = nil,
visibility: SwiftVisibility = .implicit,
name: String,
typeParameters: [String] = [],
target: SwiftType) {

var output = output
if let docComments { writeDocComment(docComments) }
if let documentation { writeDocumentationComment(documentation) }
output.beginLine(grouping: .withName("typealias"))
visibility.write(to: &output, trailingSpace: true)
output.write("typealias ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extension SwiftProjection {

public var assemblyModuleName: String { shortName + "Assembly" }

public func addAssembly(_ assembly: Assembly, documentation: DocumentationFile? = nil) {
public func addAssembly(_ assembly: Assembly, documentation: AssemblyDocumentation? = nil) {
projection.assembliesToModules[assembly] = AssemblyEntry(module: self, documentation: documentation)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ extension SwiftProjection {
}
}

static func toDocComments(_ entry: MemberEntry) -> SwiftDocComment {
static func toDocumentationComment(_ documentation: MemberDocumentation) -> SwiftDocumentationComment {
// TODO: Convert doc comments
return SwiftDocComment()
return SwiftDocumentationComment()
}

// Windows.Foundation.Collections to WindowsFoundationCollections
Expand Down
16 changes: 8 additions & 8 deletions Generator/Sources/ProjectionGenerator/SwiftProjection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import DotNetXMLDocs
public class SwiftProjection {
internal struct AssemblyEntry {
var module: Module
var documentation: DocumentationFile?
var documentation: AssemblyDocumentation?
}

public private(set) var modulesByShortName = [String: Module]()
Expand All @@ -26,27 +26,27 @@ public class SwiftProjection {
assembliesToModules[assembly]?.module
}

internal func getDocumentation(_ assembly: Assembly) -> DocumentationFile? {
internal func getDocumentation(_ assembly: Assembly) -> AssemblyDocumentation? {
assembliesToModules[assembly]?.documentation
}

internal func getDocumentation(_ typeDefinition: TypeDefinition) -> DotNetXMLDocs.MemberEntry? {
internal func getDocumentation(_ typeDefinition: TypeDefinition) -> MemberDocumentation? {
guard let documentationFile = getDocumentation(typeDefinition.assembly) else { return nil }
return documentationFile.members[.type(fullName: typeDefinition.fullName)]
}

internal func getDocumentation(_ member: Member) throws -> DotNetXMLDocs.MemberEntry? {
internal func getDocumentation(_ member: Member) throws -> MemberDocumentation? {
guard let documentationFile = getDocumentation(member.definingType.assembly) else { return nil }

let memberKey: DotNetXMLDocs.MemberKey
let memberKey: MemberDocumentationKey
switch member {
case let field as Field:
memberKey = .field(typeFullName: field.definingType.fullName, name: field.name)
memberKey = .field(declaringType: field.definingType.fullName, name: field.name)
case let event as Event:
memberKey = .event(typeFullName: event.definingType.fullName, name: event.name)
memberKey = .event(declaringType: event.definingType.fullName, name: event.name)
case let property as Property:
guard try (property.getter?.arity ?? 0) == 0 else { return nil }
memberKey = .event(typeFullName: property.definingType.fullName, name: property.name)
memberKey = .event(declaringType: property.definingType.fullName, name: property.name)
default:
return nil
}
Expand Down
Loading

0 comments on commit 5e013b6

Please sign in to comment.