Skip to content

Commit fcb0399

Browse files
committed
[PlaygroundLogger] Implemented support for logging a synthetic child named "super" for the superclassMirror.
If `mirror.superclassMirror` is non-nil, we log it as our first child before logging the remaining children.
1 parent 98b9dce commit fcb0399

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

PlaygroundLogger/PlaygroundLogger/LogEntry+Reflection.swift

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,33 @@ extension LogEntry {
8383
self = .opaque(name: name, typeName: typeName, summary: summary, preferBriefSummary: false, representation: playgroundQuickLook.opaqueRepresentation)
8484
}
8585

86+
private static let superclassLogEntryName = "super"
87+
8688
private init(structureFrom mirror: Mirror, name: String, typeName: String, summary: String) {
87-
self = .structured(name: name, typeName: typeName, summary: summary, totalChildrenCount: Int(mirror.children.count), children: mirror.children.map { LogEntry(describing: $0.value, name: $0.label) }, disposition: .init(displayStyle: mirror.displayStyle))
89+
let totalChildrenCount: Int
90+
var childEntries: [LogEntry] = []
91+
92+
// If our Mirror has a superclassMirror, then we need to include that as the first "child" (and include it in the total children count).
93+
if let superclassMirror = mirror.superclassMirror {
94+
let superclassTypeName = _typeName(superclassMirror.subjectType)
95+
childEntries.append(LogEntry(structureFrom: superclassMirror, name: LogEntry.superclassLogEntryName, typeName: superclassTypeName, summary: superclassTypeName))
96+
97+
totalChildrenCount = Int(mirror.children.count) + 1
98+
}
99+
else {
100+
totalChildrenCount = Int(mirror.children.count)
101+
}
102+
103+
// Next, we need to generate log entries for all of the "real" children of this mirror.
104+
childEntries += mirror.children.map { LogEntry(describing: $0.value, name: $0.label) }
105+
106+
self = .structured(name: name,
107+
typeName: typeName,
108+
summary: summary,
109+
totalChildrenCount: totalChildrenCount,
110+
children: childEntries,
111+
disposition: .init(displayStyle: mirror.displayStyle)
112+
)
88113
}
89114
}
90115

0 commit comments

Comments
 (0)