1 // Note: the run lines follow their respective tests, since line/column
2 // matter in this test.
4 @protocol FooTestProtocol
6 - protocolInstanceMethod : (int)value;
8 @interface Foo <FooTestProtocol> {
11 + (int)classMethod1:a withKeyword:(int)b;
17 @interface Foo (FooTestCategory)
18 + categoryClassMethod;
19 - categoryInstanceMethod;
27 @interface MyClass { }
28 + (int)MyClassMethod:(id)obj;
29 - (int)MyInstMethod:(id)x second:(id)y;
32 @interface MySubClass : MyClass { }
33 + (int)MySubClassMethod;
34 - (int)MySubInstMethod;
37 @implementation MyClass
38 + (int)MyClassMethod:(id)obj {
42 + (int)MyPrivateMethod {
46 - (int)MyInstMethod:(id)x second:(id)y {
50 - (int)MyPrivateInstMethod {
54 MyClass *getMyClass();
55 @implementation MySubClass
56 + (int)MySubClassMethod {
60 + (int)MySubPrivateMethod {
61 return [super MyPrivateMethod];
64 - (int)MySubInstMethod:(id)obj {
65 return [super MyInstMethod: obj second:obj];
68 - (int)MyInstMethod:(id)x second:(id)y {
73 void test_super_var(MySubClass *super) {
74 [super MyInstMethod: super second:super];
77 @protocol FooTestProtocol2
78 - (int)secondProtocolInstanceMethod;
81 void test_qual_id(id<FooTestProtocol,FooTestProtocol2> ptr) {
82 [ptr protocolInstanceMethod:1];
88 - (int)Method:(float)f Arg1:(int)i1 Arg2:(int)i2;
89 - (int)Method:(float)f Arg1:(int)i1 OtherArg:(id)obj;
90 - (int)Method:(float)f SomeArg:(int)i1 OtherArg:(id)obj;
91 - (int)OtherMethod:(float)f Arg1:(int)i1 Arg2:(int)i2;
94 void test_overload(Overload *ovl) {
95 [ovl Method:1 Arg1:1 OtherArg:ovl];
99 - (int)Method:(int)i, ...;
100 - (int)SentinelMethod:(int)i, ... __attribute__((sentinel(0,1)));
102 void f(Ellipsis *e) {
107 + (int)Method:(int)i;
109 + (int)Method:(float)f Arg1:(int)i1 Arg2:(int)i2;
110 + (int)Method:(float)f Arg1:(int)i1 OtherArg:(id)obj;
111 + (int)Method:(float)f SomeArg:(int)i1 OtherArg:(id)obj;
112 + (int)OtherMethod:(float)f Arg1:(int)i1 Arg2:(int)i2;
115 void test_overload2(void) {
116 [Overload2 Method:1 Arg1:1 OtherArg:ovl];
120 [x Method:1 Arg1:1 OtherArg:ovl];
121 [[x blarg] Method:1 Arg1:1 OtherArg:ovl];
122 [id Method:1 Arg1:1 OtherArg:ovl];
133 void test_ranking(B *b) {
138 void test_overload3(Overload *ovl) {
139 ovl Method:1 Arg1:1 OtherArg:ovl];
140 Overload2 Method:1 Arg1:1 OtherArg:ovl];
141 (Overload2 Method:1 Arg1:1 OtherArg:ovl]);
149 void test_redundancy(C *c) {
161 + (void)class_method3;
165 + (void)class_method4;
169 - (void)method5:(A*)a {
170 [[self class] class_method4];
174 void test_missing_open_more() {
175 A *a = A class_method3];
178 void test_block_invoke(A *(^block1)(int),
185 - (void)method:(in bycopy A*)ain result:(out byref A**)aout;
188 void test_DO(DO *d, A* a) {
189 [d method:a aout:&a];
192 @interface Nullability
193 - (nonnull A *)method:(nullable A *)param;
196 void test_Nullability(Nullability *n, A* a) {
200 // RUN: c-index-test -code-completion-at=%s:23:19 %s | FileCheck -check-prefix=CHECK-CC1 %s
201 // CHECK-CC1: {TypedText categoryClassMethod} (35)
202 // CHECK-CC1: {TypedText classMethod1:}{Placeholder (id)}{HorizontalSpace }{TypedText withKeyword:}{Placeholder (int)} (35)
203 // CHECK-CC1: {TypedText classMethod2} (35)
204 // CHECK-CC1: {TypedText instanceMethod1} (35)
205 // CHECK-CC1: {TypedText new} (35)
206 // CHECK-CC1: {TypedText protocolClassMethod} (37)
207 // CHECK-CC1: Completion contexts:
208 // CHECK-CC1-NEXT: Objective-C class method
209 // CHECK-CC1-NEXT: Container Kind: ObjCInterfaceDecl
210 // CHECK-CC1-NEXT: Container is complete
211 // CHECK-CC1-NEXT: Container USR: c:objc(cs)Foo
212 // RUN: c-index-test -code-completion-at=%s:24:8 %s | FileCheck -check-prefix=CHECK-CC2 %s
213 // CHECK-CC2: {TypedText categoryInstanceMethod}
214 // CHECK-CC2: {TypedText instanceMethod1}
215 // CHECK-CC2: {TypedText protocolInstanceMethod:}{Placeholder (int)}
216 // CHECK-CC2: Completion contexts:
217 // CHECK-CC2-NEXT: Objective-C instance method
218 // CHECK-CC2-NEXT: Container Kind: ObjCInterfaceDecl
219 // CHECK-CC2-NEXT: Container is complete
220 // CHECK-CC2-NEXT: Container USR: c:objc(cs)Foo
221 // RUN: c-index-test -code-completion-at=%s:61:17 %s | FileCheck -check-prefix=CHECK-CC3 %s
222 // CHECK-CC3: ObjCClassMethodDecl:{ResultType int}{TypedText MyClassMethod:}{Placeholder (id)}
223 // CHECK-CC3: ObjCClassMethodDecl:{ResultType int}{TypedText MyPrivateMethod}
224 // RUN: c-index-test -code-completion-at=%s:65:17 %s | FileCheck -check-prefix=CHECK-CC4 %s
225 // CHECK-CC4: ObjCInstanceMethodDecl:{ResultType int}{TypedText MyInstMethod:}{Placeholder (id)}{HorizontalSpace }{TypedText second:}{Placeholder (id)}
226 // CHECK-CC4: ObjCInstanceMethodDecl:{ResultType int}{TypedText MyPrivateInstMethod}
227 // RUN: c-index-test -code-completion-at=%s:74:10 %s | FileCheck -check-prefix=CHECK-CC5 %s
228 // CHECK-CC5: ObjCInstanceMethodDecl:{ResultType int}{TypedText MyInstMethod:}{Placeholder (id)}{HorizontalSpace }{TypedText second:}{Placeholder (id)}
229 // CHECK-CC5: ObjCInstanceMethodDecl:{ResultType int}{TypedText MySubInstMethod}
230 // RUN: c-index-test -code-completion-at=%s:82:8 %s | FileCheck -check-prefix=CHECK-CC6 %s
231 // CHECK-CC6: ObjCInstanceMethodDecl:{ResultType id}{TypedText protocolInstanceMethod:}{Placeholder (int)}
232 // CHECK-CC6: ObjCInstanceMethodDecl:{ResultType int}{TypedText secondProtocolInstanceMethod}
233 // RUN: c-index-test -code-completion-at=%s:95:8 %s | FileCheck -check-prefix=CHECK-CC7 %s
234 // CHECK-CC7: ObjCInstanceMethodDecl:{ResultType int}{TypedText Method}
235 // CHECK-CC7: ObjCInstanceMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (int)}
236 // CHECK-CC7: ObjCInstanceMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (float)}{HorizontalSpace }{TypedText Arg1:}{Placeholder (int)}{HorizontalSpace }{TypedText Arg2:}{Placeholder (int)}
237 // CHECK-CC7: ObjCInstanceMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (float)}{HorizontalSpace }{TypedText Arg1:}{Placeholder (int)}{HorizontalSpace }{TypedText OtherArg:}{Placeholder (id)}
238 // CHECK-CC7: ObjCInstanceMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (float)}{HorizontalSpace }{TypedText SomeArg:}{Placeholder (int)}{HorizontalSpace }{TypedText OtherArg:}{Placeholder (id)}
239 // CHECK-CC7: ObjCInstanceMethodDecl:{ResultType int}{TypedText OtherMethod:}{Placeholder (float)}{HorizontalSpace }{TypedText Arg1:}{Placeholder (int)}{HorizontalSpace }{TypedText Arg2:}{Placeholder (int)}
240 // RUN: c-index-test -code-completion-at=%s:95:17 %s | FileCheck -check-prefix=CHECK-CC8 %s
241 // CHECK-CC8: ObjCInstanceMethodDecl:{ResultType int}{Informative Method:}{TypedText Arg1:}{Placeholder (int)}{HorizontalSpace }{TypedText Arg2:}{Placeholder (int)}
242 // CHECK-CC8: ObjCInstanceMethodDecl:{ResultType int}{Informative Method:}{TypedText Arg1:}{Placeholder (int)}{HorizontalSpace }{TypedText OtherArg:}{Placeholder (id)}
243 // CHECK-CC8: ObjCInstanceMethodDecl:{ResultType int}{Informative Method:}{TypedText SomeArg:}{Placeholder (int)}{HorizontalSpace }{TypedText OtherArg:}{Placeholder (id)}
244 // CHECK-CC8-NOT: ObjCInstanceMethodDecl:{ResultType int}{Informative Method:}{TypedText }
245 // RUN: c-index-test -code-completion-at=%s:95:24 %s | FileCheck -check-prefix=CHECK-CC9 %s
246 // CHECK-CC9: ObjCInstanceMethodDecl:{ResultType int}{Informative Method:}{Informative Arg1:}{TypedText Arg2:}{Placeholder (int)}
247 // CHECK-CC9: ObjCInstanceMethodDecl:{ResultType int}{Informative Method:}{Informative Arg1:}{TypedText OtherArg:}{Placeholder (id)}
248 // CHECK-CC9: Objective-C selector: Method:Arg1:
249 // RUN: c-index-test -code-completion-at=%s:61:11 %s | FileCheck -check-prefix=CHECK-CCA %s
250 // CHECK-CCA: TypedefDecl:{TypedText Class} (50)
251 // CHECK-CCA-NEXT: ObjCInterfaceDecl:{TypedText Foo} (50)
252 // CHECK-CCA-NOT: FunctionDecl:{ResultType void}{TypedText func}{LeftParen (}{RightParen )} (50)
253 // CHECK-CCA:FunctionDecl:{ResultType MyClass *}{TypedText getMyClass}{LeftParen (}{RightParen )} (50)
254 // CHECK-CCA: TypedefDecl:{TypedText id} (50)
255 // CHECK-CCA: ObjCInterfaceDecl:{TypedText MyClass} (50)
256 // CHECK-CCA: ObjCInterfaceDecl:{TypedText MySubClass} (50)
257 // CHECK-CCA: {ResultType Class}{TypedText self} (34)
258 // CHECK-CCA: {TypedText super} (40)
259 // RUN: c-index-test -code-completion-at=%s:103:6 %s | FileCheck -check-prefix=CHECK-CCB %s
260 // CHECK-CCB: ObjCInstanceMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (int), ...}
261 // CHECK-CCB: ObjCInstanceMethodDecl:{ResultType int}{TypedText SentinelMethod:}{Placeholder (int), ...}{Text , nil}
262 // RUN: c-index-test -code-completion-at=%s:116:14 %s | FileCheck -check-prefix=CHECK-CCC %s
263 // CHECK-CCC: ObjCClassMethodDecl:{ResultType int}{TypedText Method}
264 // CHECK-CCC: ObjCClassMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (int)}
265 // CHECK-CCC: ObjCClassMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (float)}{HorizontalSpace }{TypedText Arg1:}{Placeholder (int)}{HorizontalSpace }{TypedText Arg2:}{Placeholder (int)}
266 // CHECK-CCC: ObjCClassMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (float)}{HorizontalSpace }{TypedText Arg1:}{Placeholder (int)}{HorizontalSpace }{TypedText OtherArg:}{Placeholder (id)}
267 // CHECK-CCC: ObjCClassMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (float)}{HorizontalSpace }{TypedText SomeArg:}{Placeholder (int)}{HorizontalSpace }{TypedText OtherArg:}{Placeholder (id)}
268 // CHECK-CCC: ObjCClassMethodDecl:{ResultType int}{TypedText OtherMethod:}{Placeholder (float)}{HorizontalSpace }{TypedText Arg1:}{Placeholder (int)}{HorizontalSpace }{TypedText Arg2:}{Placeholder (int)}
269 // RUN: c-index-test -code-completion-at=%s:116:23 %s | FileCheck -check-prefix=CHECK-CCD %s
270 // CHECK-CCD: ObjCClassMethodDecl:{ResultType int}{Informative Method:}{TypedText Arg1:}{Placeholder (int)}{HorizontalSpace }{TypedText Arg2:}{Placeholder (int)}
271 // CHECK-CCD: ObjCClassMethodDecl:{ResultType int}{Informative Method:}{TypedText Arg1:}{Placeholder (int)}{HorizontalSpace }{TypedText OtherArg:}{Placeholder (id)}
272 // CHECK-CCD: ObjCClassMethodDecl:{ResultType int}{Informative Method:}{TypedText SomeArg:}{Placeholder (int)}{HorizontalSpace }{TypedText OtherArg:}{Placeholder (id)}
273 // CHECK-CCD-NOT: ObjCClassMethodDecl:{ResultType int}{Informative Method:}{TypedText }
274 // CHECK-CCD: Objective-C selector: Method:
275 // RUN: c-index-test -code-completion-at=%s:116:30 %s | FileCheck -check-prefix=CHECK-CCE %s
276 // CHECK-CCE: ObjCClassMethodDecl:{ResultType int}{Informative Method:}{Informative Arg1:}{TypedText Arg2:}{Placeholder (int)}
277 // CHECK-CCE: ObjCClassMethodDecl:{ResultType int}{Informative Method:}{Informative Arg1:}{TypedText OtherArg:}{Placeholder (id)}
278 // RUN: c-index-test -code-completion-at=%s:61:11 %s | FileCheck -check-prefix=CHECK-CCF %s
279 // CHECK-CCF: TypedefDecl:{TypedText Class}
280 // CHECK-CCF: ObjCInterfaceDecl:{TypedText Foo}
281 // CHECK-CCF-NOT: FunctionDecl:{ResultType void}{TypedText func}{LeftParen (}{RightParen )}
282 // CHECK-CCF: TypedefDecl:{TypedText id}
283 // CHECK-CCF: ObjCInterfaceDecl:{TypedText MyClass}
284 // CHECK-CCF: ObjCInterfaceDecl:{TypedText MySubClass}
285 // CHECK-CCF: {ResultType Class}{TypedText self}
286 // CHECK-CCF: {TypedText super}
287 // RUN: c-index-test -code-completion-at=%s:120:6 %s | FileCheck -check-prefix=CHECK-CCG %s
288 // CHECK-CCG: ObjCInstanceMethodDecl:{ResultType id}{TypedText categoryInstanceMethod}
289 // CHECK-CCG: ObjCInstanceMethodDecl:{ResultType id}{TypedText instanceMethod1}
290 // CHECK-CCG: ObjCInstanceMethodDecl:{ResultType int}{TypedText Method}
291 // CHECK-CCG: ObjCInstanceMethodDecl:{ResultType int}{TypedText MyInstMethod:}{Placeholder (id)}{HorizontalSpace }{TypedText second:}{Placeholder (id)}
292 // CHECK-CCG: ObjCInstanceMethodDecl:{ResultType int}{TypedText MyPrivateInstMethod}
293 // CHECK-CCG: ObjCInstanceMethodDecl:{ResultType int}{TypedText MySubInstMethod}
294 // CHECK-CCG: ObjCInstanceMethodDecl:{ResultType id}{TypedText protocolInstanceMethod:}{Placeholder (int)}
295 // CHECK-CCG: ObjCInstanceMethodDecl:{ResultType int}{TypedText secondProtocolInstanceMethod}
296 // RUN: c-index-test -code-completion-at=%s:121:14 %s | FileCheck -check-prefix=CHECK-CCG %s
297 // RUN: c-index-test -code-completion-at=%s:122:7 %s | FileCheck -check-prefix=CHECK-CCH %s
298 // CHECK-CCH: ObjCClassMethodDecl:{ResultType id}{TypedText categoryClassMethod}
299 // CHECK-CCH: ObjCClassMethodDecl:{ResultType int}{TypedText classMethod1:}{Placeholder (id)}{HorizontalSpace }{TypedText withKeyword:}{Placeholder (int)}
300 // CHECK-CCH: ObjCClassMethodDecl:{ResultType void}{TypedText classMethod2}
301 // CHECK-CCH: ObjCClassMethodDecl:{ResultType int}{TypedText Method}
302 // CHECK-CCH: ObjCClassMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (int)}
303 // CHECK-CCH: ObjCClassMethodDecl:{ResultType int}{TypedText MyClassMethod:}{Placeholder (id)}
304 // CHECK-CCH: ObjCClassMethodDecl:{ResultType int}{TypedText MyPrivateMethod}
305 // CHECK-CCH: ObjCClassMethodDecl:{ResultType int}{TypedText MySubClassMethod}
306 // CHECK-CCH: ObjCClassMethodDecl:{ResultType int}{TypedText MySubPrivateMethod}
307 // CHECK-CCH: ObjCClassMethodDecl:{ResultType id}{TypedText new}
308 // CHECK-CCH: ObjCClassMethodDecl:{ResultType int}{TypedText OtherMethod:}{Placeholder (float)}{HorizontalSpace }{TypedText Arg1:}{Placeholder (int)}{HorizontalSpace }{TypedText Arg2:}{Placeholder (int)}
309 // CHECK-CCH: ObjCClassMethodDecl:{ResultType id}{TypedText protocolClassMethod}
310 // RUN: c-index-test -code-completion-at=%s:134:6 %s | FileCheck -check-prefix=CHECK-CCI %s
311 // CHECK-CCI: ObjCInstanceMethodDecl:{ResultType void}{TypedText method1} (37)
312 // CHECK-CCI: ObjCInstanceMethodDecl:{ResultType void}{TypedText method2} (35)
314 // RUN: c-index-test -code-completion-at=%s:150:6 %s | FileCheck -check-prefix=CHECK-REDUNDANT %s
315 // CHECK-REDUNDANT: ObjCInstanceMethodDecl:{ResultType void}{TypedText method2} (35)
316 // CHECK-REDUNDANT-NOT: ObjCInstanceMethodDecl:{ResultType void}{TypedText method2}
317 // CHECK-REDUNDANT: ObjCInstanceMethodDecl:{ResultType void}{TypedText method3} (35)
319 // RUN: c-index-test -code-completion-at=%s:170:16 %s | FileCheck -check-prefix=CHECK-CLASS-RESULT %s
320 // CHECK-CLASS-RESULT: ObjCClassMethodDecl:{ResultType void}{TypedText class_method3} (35)
321 // CHECK-CLASS-RESULT: ObjCClassMethodDecl:{ResultType void}{TypedText class_method4} (35)
323 // RUN: c-index-test -code-completion-at=%s:181:4 %s | FileCheck -check-prefix=CHECK-BLOCK-RECEIVER %s
324 // CHECK-BLOCK-RECEIVER: ObjCInterfaceDecl:{TypedText A} (50)
325 // CHECK-BLOCK-RECEIVER: ObjCInterfaceDecl:{TypedText B} (50)
326 // CHECK-BLOCK-RECEIVER: ParmDecl:{ResultType A *(^)(int)}{TypedText block1} (34)
327 // CHECK-BLOCK-RECEIVER-NEXT: ParmDecl:{ResultType id (^)(int)}{TypedText block3} (34)
329 // Test code completion with a missing opening bracket:
330 // RUN: c-index-test -code-completion-at=%s:135:5 %s | FileCheck -check-prefix=CHECK-CCI %s
331 // RUN: c-index-test -code-completion-at=%s:139:7 %s | FileCheck -check-prefix=CHECK-CC7 %s
332 // RUN: c-index-test -code-completion-at=%s:139:16 %s | FileCheck -check-prefix=CHECK-CC8 %s
333 // RUN: c-index-test -code-completion-at=%s:139:23 %s | FileCheck -check-prefix=CHECK-CC9 %s
335 // RUN: c-index-test -code-completion-at=%s:140:14 %s | FileCheck -check-prefix=CHECK-CCC %s
336 // RUN: c-index-test -code-completion-at=%s:140:23 %s | FileCheck -check-prefix=CHECK-CCD %s
337 // RUN: c-index-test -code-completion-at=%s:140:30 %s | FileCheck -check-prefix=CHECK-CCE %s
338 // RUN: c-index-test -code-completion-at=%s:141:14 %s | FileCheck -check-prefix=CHECK-CCC %s
339 // RUN: c-index-test -code-completion-at=%s:141:23 %s | FileCheck -check-prefix=CHECK-CCD %s
340 // RUN: c-index-test -code-completion-at=%s:141:30 %s | FileCheck -check-prefix=CHECK-CCE %s
342 // RUN: c-index-test -code-completion-at=%s:175:12 %s | FileCheck -check-prefix=CHECK-CLASS-RESULT %s
344 // RUN: c-index-test -code-completion-at=%s:189:6 %s | FileCheck -check-prefix=CHECK-DISTRIB-OBJECTS %s
345 // CHECK-DISTRIB-OBJECTS: ObjCInstanceMethodDecl:{ResultType void}{TypedText method:}{Placeholder (in bycopy A *)}{HorizontalSpace }{TypedText result:}{Placeholder (out byref A **)} (35)
347 // RUN: c-index-test -code-completion-at=%s:197:6 %s | FileCheck -check-prefix=CHECK-NULLABLE %s
348 // CHECK-NULLABLE: ObjCInstanceMethodDecl:{ResultType A * _Nonnull}{TypedText method:}{Placeholder (nullable A *)}
350 // Code completion results should include instance methods from RootProtocol and
351 // RootClass when completing a method invocation for a RootClass object because
352 // RootClasses metaclass subclasses from RootClass (i.e. RootClass is actually
353 // an instance of RootClass).
355 @protocol SubRootProtocol
357 - (void)subProtocolInstanceMethod;
361 @protocol RootProtocol <SubRootProtocol>
363 - (void)protocolInstanceMethod;
364 + (void)protocolClassMethod;
368 @interface RootClass <RootProtocol>
370 - (void)instanceMethod;
375 @protocol RootCategoryProtocol
377 - (void)categoryProtocolInstanceMethod;
381 @interface RootClass (Cat) <RootCategoryProtocol>
383 - (void)categoryInstanceMethod;
387 void completeAllTheRootThings() {
388 [RootClass classMethod];
391 // RUN: c-index-test -code-completion-at=%s:388:14 %s | FileCheck -check-prefix=CHECK-ROOT %s
392 // CHECK-ROOT: ObjCInstanceMethodDecl:{ResultType void}{TypedText categoryInstanceMethod} (35)
393 // CHECK-ROOT-NEXT: ObjCInstanceMethodDecl:{ResultType void}{TypedText categoryProtocolInstanceMethod} (37)
394 // CHECK-ROOT-NEXT: ObjCClassMethodDecl:{ResultType void}{TypedText classMethod} (35)
395 // CHECK-ROOT-NEXT: ObjCInstanceMethodDecl:{ResultType void}{TypedText instanceMethod} (35)
396 // CHECK-ROOT-NEXT: ObjCClassMethodDecl:{ResultType void}{TypedText protocolClassMethod} (37)
397 // CHECK-ROOT-NEXT: ObjCInstanceMethodDecl:{ResultType void}{TypedText protocolInstanceMethod} (37)
398 // CHECK-ROOT-NEXT: ObjCInstanceMethodDecl:{ResultType void}{TypedText subProtocolInstanceMethod} (37)