-
Notifications
You must be signed in to change notification settings - Fork 98
Option for specifying which access levels are included #91
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,3 +55,9 @@ extension Subscript: API { | |
|
||
extension Typealias: API {} | ||
extension Variable: API {} | ||
|
||
public enum AccessLevel: String, Codable { | ||
case `public` | ||
case `internal` | ||
case `private` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it makes sense to also the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally, I see There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess making distinction between |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,12 @@ import struct SwiftSemantics.Protocol | |
public final class Interface: Codable { | ||
public let imports: [Import] | ||
public let symbols: [Symbol] | ||
public let minimumAccessLevel: AccessLevel | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my point of view, adding this property on the interface mixes concerns. The setting for creating the documentation should not be on a structure that describes source code. I'd suggest we don't include it as a property, but instead only pass the symbols that have the correct ACL. Same goes for the extension of But I also think @mattt is the person to decide on this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with @Lukas-Stuehrk here. An As to where that determination should be made, that remains an open question. Like Lukas said, it could be done either in "model" layer (by adding a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (@johankool Don't worry about trying to make sense of my rambling commentary here. I'll provide more actionable feedback in my review) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. It didn’t feel quite right to put it here. Not quite sure what the right place would be though. |
||
|
||
public required init(imports: [Import], symbols: [Symbol]) { | ||
public required init(imports: [Import], symbols: [Symbol], minimumAccessLevel: AccessLevel) { | ||
self.imports = imports | ||
self.symbols = symbols.filter { $0.isPublic } | ||
self.symbols = symbols.filter { $0.isIncluded(minimumAccessLevel: minimumAccessLevel) } | ||
self.minimumAccessLevel = minimumAccessLevel | ||
} | ||
|
||
// MARK: - | ||
|
@@ -37,7 +39,7 @@ public final class Interface: Codable { | |
var superclasses = Set(CollectionOfOne(baseClass)) | ||
|
||
while !superclasses.isEmpty { | ||
let subclasses = Set(superclasses.flatMap { typesInheriting(from: $0) }.filter { $0.isPublic }) | ||
let subclasses = Set(superclasses.flatMap { typesInheriting(from: $0) }.filter { $0.isIncluded(minimumAccessLevel: self.minimumAccessLevel) }) | ||
defer { superclasses = subclasses } | ||
classClusters[baseClass, default: []].formUnion(subclasses) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,7 +58,26 @@ public final class Symbol { | |
|
||
return false | ||
} | ||
|
||
|
||
public var isInternal: Bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think either the implementation or the property name is highly misleading. With this implementation, a public property would return Also, the actual decision whether a symbol is internal is way more complicated. There are quite some cases to consider, especially with extensions. You can take a look at the existing implementation of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. .@Lukas-Stuehrk is correct. Determining access levels for symbols is extremely complicated in Swift. I've had to fix the implementation for |
||
if api.modifiers.contains(where: { $0.name == "private" }) { | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
public func isIncluded(minimumAccessLevel: AccessLevel) -> Bool { | ||
switch minimumAccessLevel { | ||
case .public: | ||
return isPublic | ||
case .internal: | ||
return isInternal | ||
case .private: | ||
return true | ||
} | ||
} | ||
|
||
public var isDocumented: Bool { | ||
return documentation?.isEmpty == false | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One fancy thought: Instead of using
String
as the raw representable, we could also useInt
and make the enum conform toComparable
. Then we could do nice expressions likeif minimumAccessLevel >= accessLevel
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, if it goes that route and supports
Comparable
, should have a note added that it won't be needed with Swift 5.3 thanks to SE-0266.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've already started work with the latest 5.3 snapshot to get package resources working, so I'll take a look at using automatic
Comparable
synthesis with an explicit implementation for<
in a conditional compilation block.