File: IndexedObjCMethod.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 (128 lines) | stat: -rw-r--r-- 5,990 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
@interface Test

- (int)performAction:(int)action with:(int)value; // CHECK: rename [[@LINE]]:8 -> [[@LINE]]:21, [[@LINE]]:34 -> [[@LINE]]:38

@end

@implementation Test

- (int)performAction:(int)action
       with:(int)value { // CHECK: rename [[@LINE-1]]:8 -> [[@LINE-1]]:21, [[@LINE]]:8 -> [[@LINE]]:12
    return action + value;
}

+ (void)foo:(Test*)t {
    [t performAction: 2 with: 4]; // CHECK: rename [[@LINE]]:8 -> [[@LINE]]:21, [[@LINE]]:25 -> [[@LINE]]:29
    SEL s1 = @selector(performAction:
                       with:);    // CHECK-NOT: selector [[@LINE-1]]:24 -> [[@LINE-1]]:37, [[@LINE]]:24 -> [[@LINE]]:28
    SEL s2 = @selector(performAction:); // CHECK-NOT: selector [[@LINE]]
    SEL s3 = @selector(performAction);  // CHECK-NOT: selector [[@LINE]]
    // Not indexed
    [t performAction: 1 with: 2]; // CHECK-NOT: rename [[@LINE]]
}

@end

// RUN: clang-refactor-test rename-indexed-file -no-textual-matches -name=performAction:with -new-name=foo:bar -indexed-file=%s -indexed-at=3:8 -indexed-at=9:8 -indexed-at=objc-message:15:8 -indexed-symbol-kind=objc-im %s | FileCheck %s

@interface SemicolonIsExcluded
-(void)/*A_propA4_set_decl*/setPropA4X:(int)value;
@end
// CHECK2: rename [[@LINE-2]]:29 -> [[@LINE-2]]:39

// RUN: clang-refactor-test rename-indexed-file -no-textual-matches -name=setPropA4X: -new-name=foo -indexed-file=%s -indexed-at=29:29 -indexed-symbol-kind=objc-im %s -x objective-c | FileCheck --check-prefix=CHECK2 %s

// It should be possible to have the filename as one of the compilation arguments
// RUN: clang-refactor-test rename-indexed-file -no-textual-matches -ignore-filename-for-initiation-tu -name=performAction:with: -new-name=foo:bar: -indexed-file=%s -indexed-at=3:8 -indexed-at=9:8 -indexed-at=objc-message:15:8 -indexed-symbol-kind=objc-cm %s -c %s -Wall | FileCheck %s
// RUN: clang-refactor-test rename-indexed-file -no-textual-matches -ignore-filename-for-initiation-tu -name=performAction:with: -new-name=foo:bar: -indexed-file=%s -indexed-at=3:8 -indexed-at=9:8 -indexed-at=objc-message:15:8 -indexed-symbol-kind=objc-cm %s %s -fsyntax-only | FileCheck %s

// -gmodules should be stripped to avoid -fmodule-format=obj in CC1 arguments:
// RUN: clang-refactor-test rename-indexed-file -no-textual-matches -name=performAction:with: -new-name=foo:bar: -indexed-file=%s -indexed-at=3:8 -indexed-at=9:8 -indexed-at=objc-message:15:8 -indexed-symbol-kind=objc-cm %s -fmodules -gmodules | FileCheck %s

// These texual matches should be reported as comment or selector occurrences:
// CHECK3: rename [[@LINE-40]]:8 -> [[@LINE-40]]:21, [[@LINE-40]]:34 -> [[@LINE-40]]:38
// performAction
/* performAction: with: 2 performAction */
/*! performAction+1
// performAction with
!*/
/// Hello performAction with World
/// \c performAction.

// CHECK3: comment [[@LINE-8]]:4 -> [[@LINE-8]]:17
// CHECK3-NEXT: comment [[@LINE-8]]:4 -> [[@LINE-8]]:17
// CHECK3-NEXT: comment [[@LINE-9]]:27 -> [[@LINE-9]]:40
// CHECK3-NEXT: documentation [[@LINE-9]]:5 -> [[@LINE-9]]:18
// CHECK3-NEXT: documentation [[@LINE-9]]:4 -> [[@LINE-9]]:17
// CHECK3-NEXT: documentation [[@LINE-8]]:11 -> [[@LINE-8]]:24
// CHECK3-NEXT: documentation [[@LINE-8]]:8 -> [[@LINE-8]]:21

// "performAction:with:"
// 'performAction:'with:
// CHECK3-NEXT: comment [[@LINE-2]]:5 -> [[@LINE-2]]:18
// CHECK3-NEXT: comment [[@LINE-2]]:5 -> [[@LINE-2]]:18

// CHECK3-NEXT: selector [[@LINE+1]]:11 -> [[@LINE+1]]:24, [[@LINE+1]]:25 -> [[@LINE+1]]:29
@selector(performAction:with:);
// CHECK3-NEXT: selector [[@LINE+1]]:11 -> [[@LINE+1]]:24, [[@LINE+1]]:28 -> [[@LINE+1]]:32
@selector(performAction :  with );
// CHECK3-NEXT: selector [[@LINE+2]]:19 -> [[@LINE+2]]:32, [[@LINE+2]]:46 -> [[@LINE+2]]:50
SEL s = @selector(//comment
                  performAction: /*comment*/ with
                  );
// CHECK3-NEXT: selector [[@LINE+1]]:33 -> [[@LINE+1]]:46, [[@LINE+2]]:33 -> [[@LINE+2]]:37
void call = @selector(@selector(performAction:
                                with: ));

// CHECK3-NEXT: comment [[@LINE+1]]:55
// RUN: clang-refactor-test rename-indexed-file -name=performAction:with: -new-name=foo:bar -indexed-file=%s -indexed-at=objc-cm:3:8 %s | FileCheck --check-prefix=CHECK3 %s

// These ones shouldn't:
// performAction2 PERFORMACTION performActionWith
const char *test = "performAction:with:";

@selector(performAction: with ::)
@selector(performAction:)
@selector(performAction)
@selector(performAction with)
@selector(performAction:without:)
@selector(performAction:with:somethingElse:)
@selector(performAction:with "")
@selector("performAction:with:")
@selector(with: performAction:)
selector(performAction:with)
(performAction:with:)

// CHECK3-NOT: comment
// CHECK3-NOT: documentation
// CHECK3-NOT: selector
// CHECK3-NOT: string-literal
// It should be possible to find a selector in a file without any indexed occurrences:

// CHECK4: selector [[@LINE+1]]:11
@selector(nonIndexedSelector)
// CHECK4-NEXT: comment
// CHECK4-NOT: selector

// RUN: clang-refactor-test rename-indexed-file -indexed-symbol-kind=objc-im -name=nonIndexedSelector -new-name=test -indexed-file=%s %s | FileCheck --check-prefix=CHECK4 %s
// RUN: clang-refactor-test rename-indexed-file -indexed-symbol-kind=objc-cm -name=nonIndexedSelector -new-name=test -indexed-file=%s %s | FileCheck --check-prefix=CHECK4 %s

#define MACRO doStuff
#define MACRO2(x, y) doStuff:(x) with: (y)

@interface I
- (void)doStuff:(int)x with: y;
@end

@implementation I
- (void)MACRO:(int)x with: y {
  [self MACRO2(x, y)];
}
@end

// CHECK-MACRO: macro [[@LINE-5]]:9 -> [[@LINE-5]]:9
// CHECK-MACRO-NEXT: macro [[@LINE-5]]:9 -> [[@LINE-5]]:9
// CHECK-MACRO-NEXT: rename [[@LINE-11]]:9 -> [[@LINE-11]]:16, [[@LINE-11]]:24 -> [[@LINE-11]]:28
// CHECK-MACRO-NOT: macro

// RUN: clang-refactor-test rename-indexed-file -indexed-symbol-kind=objc-im -name=doStuff:with: -new-name=foo:bar -indexed-file=%s -indexed-at=114:9 -indexed-at=118:9 -indexed-at=119:9 %s | FileCheck --check-prefix=CHECK-MACRO %s