File: extract-statements.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,744 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
@interface NSArray
+ (id)arrayWithObjects:(const id [])objects count:(unsigned long)cnt;
@end

void extractedStmtNoNeedForSemicolon(NSArray *array) {
  for (id i in array) {
    int x = 0;
  }
// CHECK1: "static void extracted(NSArray *array) {\nfor (id i in array) {\n    int x = 0;\n  }\n}\n\n"
  id lock;
  @synchronized(lock) {
    int x = 0;
  }
// CHECK1: "static void extracted(id lock) {\n@synchronized(lock) {\n    int x = 0;\n  }\n}\n\n"
  @autoreleasepool {
    int x = 0;
  }
// CHECK1: "static void extracted() {\n@autoreleasepool {\n    int x = 0;\n  }\n}\n\n"
  @try {
    int x = 0;
  } @finally {
  }
// CHECK1: "static void extracted() {\n@try {\n    int x = 0;\n  } @finally {\n  }\n}\n\n"
}

// RUN: clang-refactor-test perform -action extract -selected=%s:6:3-8:4 -selected=%s:11:3-13:4 -selected=%s:15:3-17:4 -selected=%s:19:3-22:4 %s | FileCheck --check-prefix=CHECK1 %s

@interface I

@end

@implementation I

- (int)inferReturnTypeFromReturnStatement:(int)x {
  if (x == 0) {
    return x;
  }
  if (x == 1) {
    return x + 1;
  }
  return x + 2;
}
// CHECK2: "static int extracted(int x) {\nif (x == 1) {\n    return x + 1;\n  }\n  return x + 2;\n}\n\n"
// CHECK2: "static int extracted(int x) {\nif (x == 1) {\n    return x + 1;\n  }\n}\n\n"

// RUN: clang-refactor-test perform -action extract -selected=%s:38:3-41:15 -selected=%s:38:3-40:4 %s | FileCheck --check-prefix=CHECK2 %s

@end

void partiallySelectedWithImpCastCrash(I *object) {
// partially-selected-begin: +1:3
  object;
// partially-selected-end: +1:11
// comment
// CHECK3: "static void extracted(I *object) {\nobject;\n}\n\n"
// RUN: clang-refactor-test perform -action extract -selected=partially-selected %s | FileCheck --check-prefix=CHECK3 %s
}