Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 7ee7196

Browse files
committed
Consider members of public protocol as public symbols
Resolves #12
1 parent 801ef41 commit 7ee7196

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

Sources/SwiftDoc/Symbol.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,17 @@ public final class Symbol {
4141
return true
4242
}
4343

44-
if declaration is Enumeration.Case,
45-
let enumeration = context.compactMap({ ($0 as? Symbol)?.declaration as? Enumeration }).last,
46-
enumeration.modifiers.contains(where: { $0.name == "public" }) {
47-
return true
44+
if let symbol = context.compactMap({ $0 as? Symbol }).first,
45+
symbol.declaration.modifiers.contains(where: { $0.name == "public" })
46+
{
47+
switch symbol.declaration {
48+
case is Enumeration:
49+
return declaration is Enumeration.Case
50+
case is Protocol:
51+
return declaration is Function || declaration is Variable
52+
default:
53+
break
54+
}
4855
}
4956

5057
return false

Tests/SwiftDocTests/SourceFileTests.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class SourceFileTests: XCTestCase {
2929
public struct S {}
3030
3131
/// Extension
32-
extension S: P {
32+
public extension S: P {
3333
/// Function
3434
func f() {}
3535
@@ -40,10 +40,10 @@ final class SourceFileTests: XCTestCase {
4040
/// Class
4141
open class C: P{
4242
/// Function
43-
func f() {}
43+
public func f() {}
4444
4545
/// Property
46-
var p: Any { return () }
46+
public var p: Any { return () }
4747
}
4848
4949
/// Subclass
@@ -58,6 +58,10 @@ final class SourceFileTests: XCTestCase {
5858

5959
XCTAssertEqual(sourceFile.symbols.count, 12)
6060

61+
for symbol in sourceFile.symbols {
62+
XCTAssert(symbol.isPublic, "\(symbol.declaration) isn't public")
63+
}
64+
6165
do {
6266
let `protocol` = sourceFile.symbols[0]
6367
XCTAssert(`protocol`.declaration is Protocol)

0 commit comments

Comments
 (0)