File: extract-method.m

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (57 lines) | stat: -rw-r--r-- 1,694 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

void function(int x) {
  int y = x * x;
}

@interface MethodExtraction

- (int)method;
- (void)classMethod;

@end

@implementation MethodExtraction

- (void)aMethod:(int)x withY:(int)y {
  int a = x + y;
}
// CHECK1: "- (void)extracted:(int)x y:(int)y {\nint a = x + y;\n}\n\n" [[@LINE-3]]:1 -> [[@LINE-3]]:1
// CHECK1-NEXT: "[self extracted:x y:y];" [[@LINE-3]]:3 -> [[@LINE-3]]:17
// CHECK2: "static void extracted(int x, int y) {\nint a = x + y;\n}\n\n"
// CHECK2-NEXT: "extracted(x, y);"
;
+ (void)classMethod {
  int x = 1;
  int y = function(x);
}
// CHECK1: "+ (void)extracted {\nint x = 1;\n  int y = function(x);\n}\n\n" [[@LINE-4]]:1 -> [[@LINE-4]]:1
// CHECK1-NEXT: "[self extracted];" [[@LINE-4]]:3 -> [[@LINE-3]]:23
// CHECK2: "static void extracted() {\nint x = 1;\n  int y = function(x);\n}\n\n"
// CHECK2-NEXT: "extracted();"

@end

@implementation MethodExtraction (Category)

- (void)catMethod {
  int x = [self method];
}

+ (void)catClassMethod {
  int x = function(42);
}

@end

// RUN: clang-refactor-test list-actions -at=%s:16:3 -selected=%s:16:3-16:16 %s | FileCheck --check-prefix=CHECK-METHOD %s

// CHECK-METHOD:      Extract Function{{$}}
// CHECK-METHOD-NEXT: Extract Method{{$}}

// RUN: clang-refactor-test list-actions -at=%s:3:3 -selected=%s:3:3-3:16 %s | FileCheck --check-prefix=CHECK-FUNC %s

// CHECK-FUNC:     Extract Function{{$}}
// CHECK-FUNC-NOT: Extract Method

// RUN: clang-refactor-test perform -action extract-method -selected=%s:16:3-16:16 -selected=%s:24:3-25:22 %s | FileCheck --check-prefix=CHECK1 %s
// RUN: clang-refactor-test perform -action extract -selected=%s:16:3-16:16 -selected=%s:24:3-25:22 %s | FileCheck --check-prefix=CHECK2 %s