@@ -67,30 +67,28 @@ public class SwiftAstGenerator {
6767 }
6868 }
6969
70- public func generate( ) throws {
71- let resourceKeys = Set < URLResourceKey > ( [ . nameKey, . isDirectoryKey, . isRegularFileKey] )
72- let directoryEnumerator = FileManager . default. enumerator (
73- at: srcDir,
74- includingPropertiesForKeys: Array ( resourceKeys) ,
75- options: [ . skipsPackageDescendants] ) !
76-
77- for case let fileUrl as URL in directoryEnumerator {
78- guard let resourceValues = try ? fileUrl. resourceValues ( forKeys: resourceKeys) ,
79- let isDirectory = resourceValues. isDirectory,
80- let isRegularFile = resourceValues. isRegularFile,
81- let name = resourceValues. name
82- else {
83- continue
84- }
85-
86- if isDirectory {
87- if ignoreDirectory ( name: name) {
88- directoryEnumerator. skipDescendants ( )
89- }
90- } else if isRegularFile && name. hasSuffix ( " .swift " ) {
91- parseFile ( fileUrl: fileUrl)
92- }
70+ private func iterateFilesInDirectory( _ directoryURL: URL ) throws {
71+ let contents = try FileManager . default. contentsOfDirectory ( at: directoryURL, includingPropertiesForKeys: nil , options: . skipsHiddenFiles)
72+ for item in contents {
73+ var isDirectory : ObjCBool = false
74+ if FileManager . default. fileExists ( atPath: item. path, isDirectory: & isDirectory) {
75+ if isDirectory. boolValue {
76+ if ignoreDirectory ( name: item. lastPathComponent) {
77+ continue
78+ }
79+ try iterateFilesInDirectory ( item)
80+ } else {
81+ if item. lastPathComponent. hasSuffix ( " .swift " ) {
82+ parseFile ( fileUrl: item)
83+ }
84+ }
85+ }
9386 }
87+
88+ }
89+
90+ public func generate( ) throws {
91+ try iterateFilesInDirectory ( srcDir)
9492 }
9593
9694}
0 commit comments