mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Refactor `addSyntacticRenameRanges`, adding comments to make it easier to follow and remove its dependency on the `IsFunctionLike` parameter in `RenameLoc`.
120 lines
6.3 KiB
Swift
120 lines
6.3 KiB
Swift
import func SomeModule . /*import*/someFunc
|
|
|
|
func /*no-args:def*/aFunc() -> Int {
|
|
return 1
|
|
}
|
|
|
|
func /*param-label:def*/aFunc(a: Int) {}
|
|
|
|
func /*arg-label:def*/aFunc(b a:Int) {}
|
|
|
|
func /*no-label:def*/aFunc(_ b:Int) -> Int {
|
|
return /*no-args:call*/aFunc()
|
|
}
|
|
|
|
func /*whitespace-labels:def*/aFunc( a b: Int ,_ a: Int, c c : Int) {}
|
|
|
|
func /*referenced:def*/bar(a: Int) {}
|
|
|
|
func /*varargs:def*/aFunc(c: Int...) {}
|
|
/*varargs:call*/aFunc(c: 1, 2, 3, 4)
|
|
|
|
class AStruct {
|
|
func /*method:def*/foo(a: Int, b: Int, _ c: Int) -> Int {
|
|
return a + b + c
|
|
}
|
|
|
|
func /*bar:def*/bar(_ a: Int) -> (Int) -> Int {
|
|
return {a in a};
|
|
}
|
|
|
|
static func /*infix-operator:def*/+ (left: AStruct, right: AStruct) -> AStruct {
|
|
return AStruct()
|
|
}
|
|
|
|
static prefix func /*prefix-operator:def*/- (struct: AStruct) -> AStruct {
|
|
return AStruct()
|
|
}
|
|
}
|
|
|
|
let aStruct = /*prefix-operator:call*/-AStruct() /*infix-operator:call*/+ AStruct()
|
|
/*no-args:call*/aFunc()
|
|
/*param-label:call*/aFunc(a: 2)
|
|
/*arg-label:call*/aFunc(b: /*no-args:call*/aFunc() * /*no-args:call*/aFunc())
|
|
let _ = /*no-label:call*/aFunc(3)
|
|
/*whitespace-labels:call*/aFunc( a : 2 ,2, c: 4 )
|
|
|
|
let _ = aStruct . /*method:call*/foo(a: 2, b: 3, 1)
|
|
let _ = AStruct . /*method*/foo(aStruct)(a: 1, b: 8, 10)
|
|
let _ = aStruct . /*bar:call*/bar(/*no-args:call*/aFunc())(/*no-label:call*/aFunc(2))
|
|
|
|
var a = /*referenced*/bar
|
|
var b = /*referenced*/bar(a:)
|
|
let _ = "Some text \(/*param-label:call*/aFunc(a:1)) around"
|
|
|
|
class SomeClass {
|
|
init() {}
|
|
/*init:def*/init(a: Int, b:Int, c:Int) {}
|
|
/*sub:def*/subscript(x: Int, y j: Int) -> Int {
|
|
get { return 1 }
|
|
set {}
|
|
}
|
|
}
|
|
|
|
let someClass = SomeClass();
|
|
let _ = /*init:call*/SomeClass(a:1, b:1, c:1)
|
|
let _ = SomeClass . /*init*/init(a:b:c:)
|
|
_ = someClass/*sub:ref*/[1, y: 2]
|
|
someClass/*sub:ref*/[1, y: 2] = 2
|
|
|
|
class AnotherClass {
|
|
let bar = AnotherClass()
|
|
func /*nested:def*/foo(a: Int) -> AnotherClass {}
|
|
}
|
|
|
|
AnotherClass() . /*nested:call*/foo(a: 1) . /*nested2*/bar . /*nested2*/bar . /*nested:call*/foo(a: 2) . /*nested:call*/foo(a: 3) . /*nested:unknown*/foo . foo(a: 4)
|
|
|
|
struct Memberwise {
|
|
let /*memberwise-x:def*/x: Int
|
|
let y: Int = 0
|
|
var z: Int = 2
|
|
}
|
|
_ = Memberwise(/*memberwise-x:ref*/x: 1, z: 3)
|
|
let memberwise = Memberwise.init(/*memberwise-x:ref*/x:z:)
|
|
_ = memberwise . /*memberwise-x:ref*/x
|
|
|
|
// REQUIRES: swift_swift_parser
|
|
// RUN: %empty-directory(%t.ranges)
|
|
// RUN: %refactor -find-rename-ranges -source-filename %s -pos="import" -is-function-like -old-name "someFunc(a:)" >> %t.ranges/functions_import.swift
|
|
// RUN: diff -u %S/Outputs/functions/import.swift.expected %t.ranges/functions_import.swift
|
|
// RUN: %refactor -find-rename-ranges -source-filename %s -pos="bar" -is-function-like -old-name "bar(_:)" >> %t.ranges/functions_bar.swift
|
|
// RUN: diff -u %S/Outputs/functions/bar.swift.expected %t.ranges/functions_bar.swift
|
|
// RUN: %refactor -find-rename-ranges -source-filename %s -pos="no-args" -is-function-like -old-name "aFunc()" >> %t.ranges/functions_no-args.swift
|
|
// RUN: diff -u %S/Outputs/functions/no-args.swift.expected %t.ranges/functions_no-args.swift
|
|
// RUN: %refactor -find-rename-ranges -source-filename %s -pos="param-label" -is-function-like -old-name "aFunc(a:)" >> %t.ranges/functions_param-label.swift
|
|
// RUN: diff -u %S/Outputs/functions/param-label.swift.expected %t.ranges/functions_param-label.swift
|
|
// RUN: %refactor -find-rename-ranges -source-filename %s -pos="arg-label" -is-function-like -old-name "aFunc(b:)" >> %t.ranges/functions_arg-label.swift
|
|
// RUN: diff -u %S/Outputs/functions/arg-label.swift.expected %t.ranges/functions_arg-label.swift
|
|
// RUN: %refactor -find-rename-ranges -source-filename %s -pos="no-label" -is-function-like -old-name "aFunc(_:)" >> %t.ranges/functions_no-label.swift
|
|
// RUN: diff -u %S/Outputs/functions/no-label.swift.expected %t.ranges/functions_no-label.swift
|
|
// RUN: %refactor -find-rename-ranges -source-filename %s -pos="whitespace-labels" -is-function-like -old-name "aFunc(a:_:c:)" >> %t.ranges/functions_whitespace-labels.swift
|
|
// RUN: diff -u %S/Outputs/functions/whitespace-labels.swift.expected %t.ranges/functions_whitespace-labels.swift
|
|
// RUN: %refactor -find-rename-ranges -source-filename %s -pos="referenced" -is-function-like -old-name "bar(a:)" >> %t.ranges/functions_referenced.swift
|
|
// RUN: diff -u %S/Outputs/functions/referenced.swift.expected %t.ranges/functions_referenced.swift
|
|
// RUN: %refactor -find-rename-ranges -source-filename %s -pos="varargs" -is-function-like -old-name "aFunc(c:)" >> %t.ranges/functions_varargs.swift
|
|
// RUN: diff -u %S/Outputs/functions/varargs.swift.expected %t.ranges/functions_varargs.swift
|
|
// RUN: %refactor -find-rename-ranges -source-filename %s -pos="method" -is-function-like -old-name "foo(a:b:_:)" >> %t.ranges/functions_method.swift
|
|
// RUN: diff -u %S/Outputs/functions/method.swift.expected %t.ranges/functions_method.swift
|
|
// RUN: %refactor -find-rename-ranges -source-filename %s -pos="infix-operator" -is-function-like -old-name "+(left:right:)" >> %t.ranges/functions_infix-operator.swift
|
|
// RUN: diff -u %S/Outputs/functions/infix-operator.swift.expected %t.ranges/functions_infix-operator.swift
|
|
// RUN: %refactor -find-rename-ranges -source-filename %s -pos="prefix-operator" -is-function-like -old-name "-(struct:)" >> %t.ranges/functions_prefix-operator.swift
|
|
// RUN: diff -u %S/Outputs/functions/prefix-operator.swift.expected %t.ranges/functions_prefix-operator.swift
|
|
// RUN: %refactor -find-rename-ranges -source-filename %s -pos="init" -is-function-like -old-name "init(a:b:c:)" >> %t.ranges/functions_init.swift
|
|
// RUN: diff -u %S/Outputs/functions/init.swift.expected %t.ranges/functions_init.swift
|
|
// RUN: %refactor -find-rename-ranges -source-filename %s -pos="sub" -is-function-like -old-name "subscript(_:y:)" >> %t.ranges/functions_sub.swift
|
|
// RUN: diff -u %S/Outputs/functions/sub.swift.expected %t.ranges/functions_sub.swift
|
|
// RUN: %refactor -find-rename-ranges -source-filename %s -pos="nested" -is-function-like -old-name "foo(a:)" -new-name "bar(b:)" >> %t.ranges/functions_nested.swift
|
|
// RUN: diff -u %S/Outputs/functions/nested.swift.expected %t.ranges/functions_nested.swift
|
|
// RUN: %refactor -find-rename-ranges -source-filename %s -pos="memberwise-x" -old-name "x" >> %t.ranges/functions_memberwise-x.swift
|
|
// RUN: diff -u %S/Outputs/functions/memberwise-x.swift.expected %t.ranges/functions_memberwise-x.swift
|