File: extract-repeated-expr-initiate.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 (106 lines) | stat: -rw-r--r-- 4,691 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106

@interface Base

@end

@interface Object: Base {
  int ivar;
}

- (int)instanceMethod;

@property int prop;
@property void (^block)();

@end

@interface Wrapper

- (Object *)returnsObject:(int)arg;

+ (Object *)classMethodReturnsObject;

@property(class) Object *classObject;

@property Object *object;

@end

void test(Wrapper *wrapper) {
  [[wrapper returnsObject: 42] instanceMethod];
  [[wrapper returnsObject: 42] prop];
// CHECK1: Initiated the 'extract-repeated-expr-into-var' action at [[@LINE-2]]:4
// CHECK2: Initiated the 'extract-repeated-expr-into-var' action at [[@LINE-2]]:4

  wrapper.object.prop;
  [wrapper.object instanceMethod];
// CHECK3: Initiated the 'extract-repeated-expr-into-var' action at [[@LINE-2]]:3
// CHECK4: Initiated the 'extract-repeated-expr-into-var' action at [[@LINE-2]]:4

  [[wrapper object] block];
  [[wrapper object] instanceMethod];
// CHECK5: Initiated the 'extract-repeated-expr-into-var' action at [[@LINE-2]]:4
// CHECK6: Initiated the 'extract-repeated-expr-into-var' action at [[@LINE-2]]:4

  [[Wrapper classMethodReturnsObject] instanceMethod];
  [[Wrapper classMethodReturnsObject] prop];
// CHECK7: Initiated the 'extract-repeated-expr-into-var' action at [[@LINE-2]]:4
// CHECK8: Initiated the 'extract-repeated-expr-into-var' action at [[@LINE-2]]:4

  Wrapper.classObject.prop;
  if (1)
    [Wrapper.classObject instanceMethod];
// CHECK9: Initiated the 'extract-repeated-expr-into-var' action at [[@LINE-3]]:3
// CHECK10: Initiated the 'extract-repeated-expr-into-var' action at [[@LINE-2]]:6
}

// RUN: clang-refactor-test initiate -action extract-repeated-expr-into-var -in=%s:30:4-31 %s -fblocks | FileCheck --check-prefix=CHECK1 %s
// RUN: clang-refactor-test initiate -action extract-repeated-expr-into-var -in=%s:31:4-31 %s -fblocks | FileCheck --check-prefix=CHECK2 %s
// RUN: not clang-refactor-test initiate -action extract-repeated-expr-into-var -in=%s:30:1-3 -in=%s:30:32-48 %s 2>&1 | FileCheck --check-prefix=CHECK-NO %s

// RUN: clang-refactor-test initiate -action extract-repeated-expr-into-var -in=%s:35:3-17 %s -fblocks | FileCheck --check-prefix=CHECK3 %s
// RUN: clang-refactor-test initiate -action extract-repeated-expr-into-var -in=%s:36:4-18 %s -fblocks | FileCheck --check-prefix=CHECK4 %s
// RUN: not clang-refactor-test initiate -action extract-repeated-expr-into-var -in=%s:35:18-23 %s 2>&1 | FileCheck --check-prefix=CHECK-NO %s

// RUN: clang-refactor-test initiate -action extract-repeated-expr-into-var -in=%s:40:4-20 %s -fblocks | FileCheck --check-prefix=CHECK5 %s
// RUN: clang-refactor-test initiate -action extract-repeated-expr-into-var -in=%s:41:4-20 %s -fblocks | FileCheck --check-prefix=CHECK6 %s
// RUN: not clang-refactor-test initiate -action extract-repeated-expr-into-var -in=%s:40:21-28 %s 2>&1 | FileCheck --check-prefix=CHECK-NO %s

// RUN: clang-refactor-test initiate -action extract-repeated-expr-into-var -in=%s:45:4-38 %s -fblocks | FileCheck --check-prefix=CHECK7 %s
// RUN: clang-refactor-test initiate -action extract-repeated-expr-into-var -in=%s:46:4-38 %s -fblocks | FileCheck --check-prefix=CHECK8 %s
// RUN: not clang-refactor-test initiate -action extract-repeated-expr-into-var -in=%s:45:39-55 %s 2>&1 | FileCheck --check-prefix=CHECK-NO %s

// RUN: clang-refactor-test initiate -action extract-repeated-expr-into-var -in=%s:50:3-22 %s -fblocks | FileCheck --check-prefix=CHECK9 %s
// RUN: clang-refactor-test initiate -action extract-repeated-expr-into-var -in=%s:52:6-25 %s -fblocks | FileCheck --check-prefix=CHECK10 %s
// RUN: not clang-refactor-test initiate -action extract-repeated-expr-into-var -in=%s:50:23-28 -in=%s:51:1-9 %s 2>&1 | FileCheck --check-prefix=CHECK-NO %s

// CHECK-NO: Failed to initiate the refactoring action!

void testInvalidMethod(Wrapper *ref) {
  if (2)
    [[ref classObject] instanceMethod];
  [ref classObject].block();
}
// RUN: not clang-refactor-test initiate -action extract-repeated-expr-into-var -in=%s:81:6-23 %s 2>&1 | FileCheck --check-prefix=CHECK-NO %s

@interface ImplicitPropertyWithoutGetter
- (void) setValue: (int) value;
@end
void implicitPropertyWithoutGetter(ImplicitPropertyWithoutGetter *x) {
  x.value = 0;
  x.value = 1;
}

// RUN: not clang-refactor-test initiate -action extract-repeated-expr-into-var -at=%s:90:3 %s 2>&1 | FileCheck --check-prefix=CHECK-NO %s

// Prohibit ininiation in macros:

#define MACROREF(X) X.object

void prohibitMacroExpr(Wrapper *wrapper) {
  // macro-prohibited: +1:3
  wrapper.object.prop = 0;
  MACROREF(wrapper).prop = 1;
}

// RUN: not clang-refactor-test initiate -action extract-repeated-expr-into-var -at=macro-prohibited %s 2>&1 | FileCheck --check-prefix=CHECK-NO %s