From 83b9aa91f1ebed71930559832212bcc886f5c771 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Tue, 1 Aug 2023 06:54:50 -0700 Subject: [PATCH] Adjustments because MemberAccessExpr represents the member name as DeclReferenceExpr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We need to take the extra nesting level into account when detecting a member access based on the identifiers name in ActionGenerators.swift. The extra nesting level changes the way the inside out rewriter generates edits because the accessed member’s name is now one further nesting level deep. --- .../StressTester/ActionGenerators.swift | 18 +++++++++--------- .../ActionGeneratorTests.swift | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/SourceKitStressTester/Sources/StressTester/ActionGenerators.swift b/SourceKitStressTester/Sources/StressTester/ActionGenerators.swift index 6ed12af..dbf065d 100644 --- a/SourceKitStressTester/Sources/StressTester/ActionGenerators.swift +++ b/SourceKitStressTester/Sources/StressTester/ActionGenerators.swift @@ -512,15 +512,15 @@ private struct ActionToken { let name = SwiftName(base: token.text, labels: callArgs) return ExpectedResult(name: name, kind: kind) } - } - if let parent = parent.as(MemberAccessExprSyntax.self), parent.name == token { - if let refArgs = parent.declNameArguments { - let name = SwiftName(base: token.text, labels: refArgs.arguments.map{ $0.name.text }) - return ExpectedResult(name: name, kind: .reference) - } - if let (kind, callArgs) = getParentArgs(of: parent) { - let name = SwiftName(base: token.text, labels: callArgs) - return ExpectedResult(name: name, kind: kind) + if let parentsParent = parent.parent?.as(MemberAccessExprSyntax.self), parentsParent.name == token { + if let refArgs = parentsParent.declNameArguments { + let name = SwiftName(base: token.text, labels: refArgs.arguments.map{ $0.name.text }) + return ExpectedResult(name: name, kind: .reference) + } + if let (kind, callArgs) = getParentArgs(of: parentsParent) { + let name = SwiftName(base: token.text, labels: callArgs) + return ExpectedResult(name: name, kind: kind) + } } } let name = SwiftName(base: token.text, labels: []) diff --git a/SourceKitStressTester/Tests/StressTesterToolTests/ActionGeneratorTests.swift b/SourceKitStressTester/Tests/StressTesterToolTests/ActionGeneratorTests.swift index 5ce3820..fc2edae 100644 --- a/SourceKitStressTester/Tests/StressTesterToolTests/ActionGeneratorTests.swift +++ b/SourceKitStressTester/Tests/StressTesterToolTests/ActionGeneratorTests.swift @@ -188,13 +188,13 @@ class ActionGeneratorTests: XCTestCase { } XCTAssertEqual(edits, [ Action.replaceText(offset: 0, length: 9, text: ""), - Action.replaceText(offset: 0, length: 0, text: "."), // . - Action.replaceText(offset: 1, length: 0, text: "c"), // .c + Action.replaceText(offset: 0, length: 0, text: "c"), // c + Action.replaceText(offset: 0, length: 0, text: "."), // .c Action.replaceText(offset: 0, length: 0, text: "["), // [.c Action.replaceText(offset: 3, length: 0, text: "]"), // [.c] Action.replaceText(offset: 0, length: 0, text: "a"), // a[.c] - Action.replaceText(offset: 1, length: 0, text: "."), // a.[.c] - Action.replaceText(offset: 2, length: 0, text: "b"), // a.b[.c] + Action.replaceText(offset: 1, length: 0, text: "b"), // ab[.c] + Action.replaceText(offset: 1, length: 0, text: "."), // a.b[.c] Action.replaceText(offset: 3, length: 0, text: "("), // a.b([.c] Action.replaceText(offset: 8, length: 0, text: ")"), // a.b([.c]) ])