Skip to content

Commit 6b06cf6

Browse files
committed
Add a walk method to SyntaxRewriter
1 parent 6bb19ef commit 6b06cf6

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxRewriterFile.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,5 +335,17 @@ let syntaxRewriterFile = SourceFileSyntax(leadingTrivia: copyrightHeader) {
335335
}
336336
"""
337337
)
338+
339+
DeclSyntax(
340+
"""
341+
/// Rewrite `node` and anchor, making sure that the rewritten node also has
342+
/// a parent if `node` had one.
343+
public func rewrite(_ node: Syntax) -> Syntax {
344+
let rewritten = self.visit(node)
345+
let arena = SyntaxArena()
346+
return Syntax(node.data.replacingSelf(rewritten.raw, arena: arena))
347+
}
348+
"""
349+
)
338350
}
339351
}

Sources/SwiftSyntax/generated/SyntaxRewriter.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6941,4 +6941,12 @@ open class SyntaxRewriter {
69416941
return node
69426942
}
69436943
}
6944+
6945+
/// Rewrite `node` and anchor, making sure that the rewritten node also has
6946+
/// a parent if `node` had one.
6947+
public func rewrite(_ node: Syntax) -> Syntax {
6948+
let rewritten = self.visit(node)
6949+
let arena = SyntaxArena()
6950+
return Syntax(node.data.replacingSelf(rewritten.raw, arena: arena))
6951+
}
69446952
}

0 commit comments

Comments
 (0)