Adjust accessibility to match enclosing container.
This commit is contained in:
parent
cd58a7f09e
commit
1d31b0634c
|
@ -32,3 +32,25 @@ public enum Accessibility: String {
|
||||||
return self != .Private && self != .FilePrivate
|
return self != .Private && self != .FilePrivate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension Accessibility: Comparable {
|
||||||
|
/// How open is this accessibility. The higher number the more accessible.
|
||||||
|
private var openness: Int {
|
||||||
|
switch self {
|
||||||
|
case .Open:
|
||||||
|
return 4
|
||||||
|
case .Public:
|
||||||
|
return 3
|
||||||
|
case .Internal:
|
||||||
|
return 2
|
||||||
|
case .FilePrivate:
|
||||||
|
return 1
|
||||||
|
case .Private:
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static func < (lhs: Accessibility, rhs: Accessibility) -> Bool {
|
||||||
|
return lhs.openness < rhs.openness
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -21,15 +21,29 @@ public protocol ContainerToken: Token, HasAccessibility {
|
||||||
|
|
||||||
extension ContainerToken {
|
extension ContainerToken {
|
||||||
public func serialize() -> [String : Any] {
|
public func serialize() -> [String : Any] {
|
||||||
let properties = children.compactMap { $0 as? InstanceVariable }
|
func withAdjustedAccessibility(token: Token & HasAccessibility) -> Token & HasAccessibility {
|
||||||
|
// We only want to adjust tokens that are accessible and lower than the enclosing type
|
||||||
|
guard token.accessibility.isAccessible && token.accessibility < accessibility else { return token }
|
||||||
|
var mutableToken = token
|
||||||
|
mutableToken.accessibility = accessibility
|
||||||
|
return mutableToken
|
||||||
|
}
|
||||||
|
|
||||||
|
let accessibilityAdjustedChildren = children.map { child -> Token in
|
||||||
|
guard let childWithAccessibility = child as? HasAccessibility & Token else { return child }
|
||||||
|
return withAdjustedAccessibility(token: childWithAccessibility)
|
||||||
|
}
|
||||||
|
|
||||||
|
let properties = accessibilityAdjustedChildren.compactMap { $0 as? InstanceVariable }
|
||||||
|
InstanceVariable }
|
||||||
.filter { $0.accessibility.isAccessible }
|
.filter { $0.accessibility.isAccessible }
|
||||||
.map { $0.serializeWithType() }
|
.map { $0.serializeWithType() }
|
||||||
|
|
||||||
let methods = children.compactMap { $0 as? Method }
|
let methods = accessibilityAdjustedChildren.compactMap { $0 as? Method }
|
||||||
.filter { $0.accessibility.isAccessible && !$0.isInit && !$0.isDeinit }
|
.filter { $0.accessibility.isAccessible && !$0.isInit && !$0.isDeinit }
|
||||||
.map { $0.serializeWithType() }
|
.map { $0.serializeWithType() }
|
||||||
|
|
||||||
let initializers = children.compactMap { $0 as? Method }
|
let initializers = accessibilityAdjustedChildren.compactMap { $0 as? Method }
|
||||||
.filter { $0.accessibility.isAccessible && $0.isInit && !$0.isDeinit }
|
.filter { $0.accessibility.isAccessible && $0.isInit && !$0.isDeinit }
|
||||||
.map { $0.serializeWithType() }
|
.map { $0.serializeWithType() }
|
||||||
|
|
||||||
|
@ -42,7 +56,7 @@ extension ContainerToken {
|
||||||
"name": name,
|
"name": name,
|
||||||
"accessibility": accessibility.sourceName,
|
"accessibility": accessibility.sourceName,
|
||||||
"isAccessible": accessibility.isAccessible,
|
"isAccessible": accessibility.isAccessible,
|
||||||
"children": children.map { $0.serializeWithType() },
|
"children": accessibilityAdjustedChildren.map { $0.serializeWithType() },
|
||||||
"properties": properties,
|
"properties": properties,
|
||||||
"methods": methods,
|
"methods": methods,
|
||||||
"initializers": implementation ? [] : initializers,
|
"initializers": implementation ? [] : initializers,
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
// Copyright © 2016 Brightify. All rights reserved.
|
// Copyright © 2016 Brightify. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#warning("TODO: Create a new library and move this file to the library to ensure the use case is the same as our users'")
|
||||||
import class Foundation.NSArray ;import Foundation
|
import class Foundation.NSArray ;import Foundation
|
||||||
|
|
||||||
@available(iOS 42.0, *)
|
@available(iOS 42.0, *)
|
||||||
|
@ -267,23 +268,22 @@ public class InternalFieldsInPublicClass {
|
||||||
internal func function() { }
|
internal func function() { }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PublicClassWithInternalFieldsUsingPublicType {
|
#warning("TODO: When this file is moved to a separate library, uncomment and test this code compiles.")
|
||||||
internal var internalField: InternalType = InternalType()
|
//public class PublicClassWithInternalFieldsUsingPublicType {
|
||||||
var internalField2: InternalType = InternalType()
|
// internal var internalField: InternalType = InternalType()
|
||||||
func internalFunc(internalType: InternalType) {
|
// var internalField2: InternalType = InternalType()
|
||||||
}
|
// func internalFunc(internalType: InternalType) {
|
||||||
|
// }
|
||||||
internal var internalField3: PublicType = PublicType()
|
//
|
||||||
var internalField4: PublicType = PublicType()
|
// internal var internalField3: PublicType = PublicType()
|
||||||
func internalFunc(publicType: PublicType) {
|
// var internalField4: PublicType = PublicType()
|
||||||
}
|
// func internalFunc(publicType: PublicType) {
|
||||||
}
|
// }
|
||||||
|
//}
|
||||||
class InternalType {
|
//class InternalType {
|
||||||
}
|
//}
|
||||||
|
//public class PublicType {
|
||||||
public class PublicType {
|
//}
|
||||||
}
|
|
||||||
|
|
||||||
class FinalFields {
|
class FinalFields {
|
||||||
final var field: Int? = nil
|
final var field: Int? = nil
|
||||||
|
|
Loading…
Reference in New Issue