Skip to content

Commit 6023654

Browse files
committed
last refactor
1 parent 91b7c58 commit 6023654

7 files changed

Lines changed: 26 additions & 33 deletions

File tree

Sources/TokenVisitor/StructureProperty.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import SwiftSyntax
4141
/// - Function declaration "name" property → StructureValue with identifier text
4242
/// - Function declaration "body" property → Reference to "CodeBlockSyntax"
4343
/// - Missing optional property → nil value with just the property name
44-
package struct StructureProperty: Codable, Equatable {
44+
package struct StructureProperty: Codable, Equatable, Sendable {
4545
// MARK: - String Constants
4646

4747
/// Property name for collection element type information.
@@ -107,7 +107,7 @@ package struct StructureProperty: Codable, Equatable {
107107
/// - type: The syntax node type (will be converted to string)
108108
internal init(reference name: String, type: Any) {
109109
let typeString = "\(type)"
110-
self.init(name: name, value: StructureValue(text: typeString), ref: typeString)
110+
self.init(name: name, value: StructureValue(value: type), ref: typeString)
111111
}
112112

113113
/// Creates a StructureProperty for a primitive value.
@@ -116,7 +116,7 @@ package struct StructureProperty: Codable, Equatable {
116116
/// - name: The property name
117117
/// - value: The primitive value (will be converted to string)
118118
internal init(primitive name: String, value: Any) {
119-
self.init(name: name, value: StructureValue(text: "\(value)"), ref: nil)
119+
self.init(name: name, value: StructureValue(value: value), ref: nil)
120120
}
121121

122122
internal init(token name: String, tokenSyntax: TokenSyntax) {

Sources/TokenVisitor/StructureValue.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,22 @@ import Foundation
4040
/// - Token value: text="let", kind="keyword(SwiftSyntax.Keyword.let)"
4141
/// - Type reference: text="VariableDeclSyntax", kind=nil
4242
/// - Literal value: text="42", kind="integerLiteral(42)"
43-
package struct StructureValue: Codable, Equatable {
43+
package struct StructureValue: Codable, Equatable, Sendable {
4444
/// The string representation of this value.
4545
/// Contains the actual text content or type name.
46-
package let text: String
46+
private let text: String
4747

4848
/// Optional kind information that provides additional context about the value type.
4949
/// Present for tokens to indicate their specific token kind (e.g., "keyword", "identifier").
5050
/// Nil for simple text values and type references.
51-
package let kind: String?
51+
private let kind: String?
5252

5353
/// Creates a new StructureValue with the specified content.
5454
///
5555
/// - Parameters:
5656
/// - text: The string representation of the value
5757
/// - kind: Optional kind information for additional context
58-
package init(text: String, kind: String? = nil) {
58+
internal init(text: String, kind: String? = nil) {
5959
self.text = text
6060
self.kind = kind
6161
}
@@ -65,8 +65,7 @@ package struct StructureValue: Codable, Equatable {
6565
/// - Parameters:
6666
/// - value: Any value that will be converted to a string
6767
/// - kind: Optional kind information for additional context
68-
package init(value: Any, kind: String? = nil) {
69-
self.text = "\(value)"
70-
self.kind = kind
68+
internal init(value: Any, kind: String? = nil) {
69+
self.init(text: "\(value)", kind: kind)
7170
}
7271
}

Sources/TokenVisitor/SyntaxClassifiable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import Foundation
3434
///
3535
/// This protocol allows syntax nodes to self-identify their classification,
3636
/// making the classification process more type-safe and extensible.
37-
package protocol SyntaxClassifiable {
37+
package protocol SyntaxClassifiable: Sendable {
3838
/// Returns the semantic classification of this syntax node type.
3939
static var syntaxType: SyntaxType { get }
4040
}

Sources/TokenVisitor/SyntaxType.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import Foundation
3939
///
4040
/// The classification is based on the SwiftSyntax type hierarchy and groups
4141
/// related syntax elements into meaningful categories.
42-
package enum SyntaxType: String, Codable, Equatable {
42+
package enum SyntaxType: String, Codable, Equatable, Sendable {
4343
/// Declaration syntax elements.
4444
/// Includes: struct, class, enum, func, var, let, import, protocol, extension, etc.
4545
case decl

Sources/TokenVisitor/Token.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,26 @@ import Foundation
4040
/// newlines, comments, and other formatting elements that don't directly
4141
/// participate in the Swift language grammar but are important for
4242
/// code reconstruction and analysis.
43-
package struct Token: Codable, Equatable {
43+
package struct Token: Codable, Equatable, Sendable {
4444
/// The classification of this token (e.g., "keyword", "identifier", "integerLiteral").
4545
/// Corresponds to SwiftSyntax TokenKind descriptions.
46-
package let kind: String
46+
private let kind: String
4747

4848
/// Trivia that appears before this token.
4949
/// Includes whitespace, comments, and other non-semantic text preceding the token.
50-
package var leadingTrivia: String
50+
internal private(set) var leadingTrivia: String
5151

5252
/// Trivia that appears after this token.
5353
/// Includes whitespace, comments, and other non-semantic text following the token.
54-
package var trailingTrivia: String
54+
internal private(set) var trailingTrivia: String
5555

5656
/// Creates a new Token with the specified properties.
5757
///
5858
/// - Parameters:
5959
/// - kind: The token classification
6060
/// - leadingTrivia: Text appearing before the token
6161
/// - trailingTrivia: Text appearing after the token
62-
package init(kind: String, leadingTrivia: String, trailingTrivia: String) {
62+
internal init(kind: String, leadingTrivia: String, trailingTrivia: String) {
6363
self.kind = kind
6464
self.leadingTrivia = leadingTrivia
6565
self.trailingTrivia = trailingTrivia

Sources/TokenVisitor/TokenVisitor.swift

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,25 +128,19 @@ internal final class TokenVisitor<NodeType: TreeNodeProtocol>: SyntaxRewriter {
128128
// Store the actual token text content
129129
current?.text = token.text
130130

131+
// Process leading trivia (whitespace, comments before the token)
132+
let leadingTrivia = token.leadingTrivia.map(processTriviaPiece).joined()
133+
134+
// Process trailing trivia (whitespace, comments after the token)
135+
let trailingTrivia = token.trailingTrivia.map(processTriviaPiece).joined()
136+
131137
// Create token metadata with kind information
132138
current?.token = Token(
133139
kind: "\(token.tokenKind)",
134-
leadingTrivia: .empty,
135-
trailingTrivia: .empty
140+
leadingTrivia: leadingTrivia,
141+
trailingTrivia: trailingTrivia
136142
)
137143

138-
// Process leading trivia (whitespace, comments before the token)
139-
for piece in token.leadingTrivia {
140-
let trivia = processTriviaPiece(piece)
141-
current?.token?.leadingTrivia += trivia
142-
}
143-
144-
// Process trailing trivia (whitespace, comments after the token)
145-
for piece in token.trailingTrivia {
146-
let trivia = processTriviaPiece(piece)
147-
current?.token?.trailingTrivia += trivia
148-
}
149-
150144
return token
151145
}
152146

Sources/TokenVisitor/TreeNodeProtocol+Extensions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ extension TreeNodeProtocol {
179179
}
180180

181181
extension String {
182-
fileprivate static let defaultFileName = ""
182+
internal static let defaultFileName = ""
183183

184-
fileprivate init?(_ keyPath: AnyKeyPath) {
184+
internal init?(_ keyPath: AnyKeyPath) {
185185
let keyPathString = String(describing: keyPath)
186186

187187
// Extract the last component after the last dot

0 commit comments

Comments
 (0)