complete-objc-message.m revision 3e64d56185f0bf7dbd536c1b3ecbc853c22a9184
1// Note: the run lines follow their respective tests, since line/column 2// matter in this test. 3#define nil (void*)0 4@protocol FooTestProtocol 5+ protocolClassMethod; 6- protocolInstanceMethod : (int)value; 7@end 8@interface Foo <FooTestProtocol> { 9 void *isa; 10} 11+ (int)classMethod1:a withKeyword:(int)b; 12+ (void)classMethod2; 13+ new; 14- instanceMethod1; 15@end 16 17@interface Foo (FooTestCategory) 18+ categoryClassMethod; 19- categoryInstanceMethod; 20@end 21 22void func() { 23 Foo *obj = [Foo new]; 24 [obj xx]; 25} 26 27@interface MyClass { } 28+ (int)MyClassMethod:(id)obj; 29- (int)MyInstMethod:(id)x second:(id)y; 30@end 31 32@interface MySubClass : MyClass { } 33+ (int)MySubClassMethod; 34- (int)MySubInstMethod; 35@end 36 37@implementation MyClass 38+ (int)MyClassMethod:(id)obj { 39 return 0; 40} 41 42+ (int)MyPrivateMethod { 43 return 1; 44} 45 46- (int)MyInstMethod:(id)x second:(id)y { 47 return 2; 48} 49 50- (int)MyPrivateInstMethod { 51 return 3; 52} 53@end 54MyClass *getMyClass(); 55@implementation MySubClass 56+ (int)MySubClassMethod { 57 return 2; 58} 59 60+ (int)MySubPrivateMethod { 61 return [super MyPrivateMethod]; 62} 63 64- (int)MySubInstMethod:(id)obj { 65 return [super MyInstMethod: obj second:obj]; 66} 67 68- (int)MyInstMethod:(id)x second:(id)y { 69 return 3; 70} 71@end 72 73void test_super_var(MySubClass *super) { 74 [super MyInstMethod: super second:super]; 75} 76 77@protocol FooTestProtocol2 78- (int)secondProtocolInstanceMethod; 79@end 80 81void test_qual_id(id<FooTestProtocol,FooTestProtocol2> ptr) { 82 [ptr protocolInstanceMethod:1]; 83} 84 85@interface Overload 86- (int)Method:(int)i; 87- (int)Method; 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; 92@end 93 94void test_overload(Overload *ovl) { 95 [ovl Method:1 Arg1:1 OtherArg:ovl]; 96} 97 98@interface Ellipsis 99- (int)Method:(int)i, ...; 100- (int)SentinelMethod:(int)i, ... __attribute__((sentinel(0,1))); 101@end 102void f(Ellipsis *e) { 103 [e Method:1, 2, 3]; 104} 105 106@interface Overload2 107+ (int)Method:(int)i; 108+ (int)Method; 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; 113@end 114 115void test_overload2(void) { 116 [Overload2 Method:1 Arg1:1 OtherArg:ovl]; 117} 118 119void msg_id(id x) { 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]; 123} 124 125@interface A 126- (void)method1; 127@end 128 129@interface B : A 130- (void)method2; 131@end 132 133void test_ranking(B *b) { 134 [b method1]; 135 b method1]; 136} 137 138void 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]); 142} 143 144@interface C : B 145- (void)method2; 146- (void)method3; 147@end 148 149void test_redundancy(C *c) { 150 [c method2]; 151}; 152 153@protocol P 154- (Class)class; 155@end 156 157@interface A () <P> 158@end 159 160@interface A () 161+ (void)class_method3; 162@end 163 164@interface A (Cat) 165+ (void)class_method4; 166@end 167 168@implementation A 169- (void)method5:(A*)a { 170 [[self class] class_method4]; 171} 172@end 173 174void test_missing_open_more() { 175 A *a = A class_method3]; 176} 177 178void test_block_invoke(A *(^block1)(int), 179 int (^block2)(int), 180 id (^block3)(int)) { 181 [block1(5) init]; 182} 183 184// RUN: c-index-test -code-completion-at=%s:23:19 %s | FileCheck -check-prefix=CHECK-CC1 %s 185// CHECK-CC1: {TypedText categoryClassMethod} 186// CHECK-CC1: {TypedText classMethod1:}{Placeholder (id)}{HorizontalSpace }{TypedText withKeyword:}{Placeholder (int)} 187// CHECK-CC1: {TypedText classMethod2} 188// CHECK-CC1: {TypedText new} 189// CHECK-CC1: {TypedText protocolClassMethod} 190// RUN: c-index-test -code-completion-at=%s:24:8 %s | FileCheck -check-prefix=CHECK-CC2 %s 191// CHECK-CC2: {TypedText categoryInstanceMethod} 192// CHECK-CC2: {TypedText instanceMethod1} 193// CHECK-CC2: {TypedText protocolInstanceMethod:}{Placeholder (int)} 194// RUN: c-index-test -code-completion-at=%s:61:16 %s | FileCheck -check-prefix=CHECK-CC3 %s 195// CHECK-CC3: ObjCClassMethodDecl:{ResultType int}{TypedText MyClassMethod:}{Placeholder (id)} 196// CHECK-CC3: ObjCClassMethodDecl:{ResultType int}{TypedText MyPrivateMethod} 197// RUN: c-index-test -code-completion-at=%s:65:16 %s | FileCheck -check-prefix=CHECK-CC4 %s 198// CHECK-CC4: ObjCInstanceMethodDecl:{ResultType int}{TypedText MyInstMethod:}{Placeholder (id)}{HorizontalSpace }{TypedText second:}{Placeholder (id)} 199// CHECK-CC4: ObjCInstanceMethodDecl:{ResultType int}{TypedText MyPrivateInstMethod} 200// RUN: c-index-test -code-completion-at=%s:74:9 %s | FileCheck -check-prefix=CHECK-CC5 %s 201// CHECK-CC5: ObjCInstanceMethodDecl:{ResultType int}{TypedText MyInstMethod:}{Placeholder (id)}{HorizontalSpace }{TypedText second:}{Placeholder (id)} 202// CHECK-CC5: ObjCInstanceMethodDecl:{ResultType int}{TypedText MySubInstMethod} 203// RUN: c-index-test -code-completion-at=%s:82:8 %s | FileCheck -check-prefix=CHECK-CC6 %s 204// CHECK-CC6: ObjCInstanceMethodDecl:{ResultType id}{TypedText protocolInstanceMethod:}{Placeholder (int)} 205// CHECK-CC6: ObjCInstanceMethodDecl:{ResultType int}{TypedText secondProtocolInstanceMethod} 206// RUN: c-index-test -code-completion-at=%s:95:8 %s | FileCheck -check-prefix=CHECK-CC7 %s 207// CHECK-CC7: ObjCInstanceMethodDecl:{ResultType int}{TypedText Method} 208// CHECK-CC7: ObjCInstanceMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (int)} 209// CHECK-CC7: ObjCInstanceMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (float)}{HorizontalSpace }{TypedText Arg1:}{Placeholder (int)}{HorizontalSpace }{TypedText Arg2:}{Placeholder (int)} 210// CHECK-CC7: ObjCInstanceMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (float)}{HorizontalSpace }{TypedText Arg1:}{Placeholder (int)}{HorizontalSpace }{TypedText OtherArg:}{Placeholder (id)} 211// CHECK-CC7: ObjCInstanceMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (float)}{HorizontalSpace }{TypedText SomeArg:}{Placeholder (int)}{HorizontalSpace }{TypedText OtherArg:}{Placeholder (id)} 212// CHECK-CC7: ObjCInstanceMethodDecl:{ResultType int}{TypedText OtherMethod:}{Placeholder (float)}{HorizontalSpace }{TypedText Arg1:}{Placeholder (int)}{HorizontalSpace }{TypedText Arg2:}{Placeholder (int)} 213// RUN: c-index-test -code-completion-at=%s:95:17 %s | FileCheck -check-prefix=CHECK-CC8 %s 214// CHECK-CC8: ObjCInstanceMethodDecl:{ResultType int}{Informative Method:}{TypedText Arg1:}{Placeholder (int)}{HorizontalSpace }{TypedText Arg2:}{Placeholder (int)} 215// CHECK-CC8: ObjCInstanceMethodDecl:{ResultType int}{Informative Method:}{TypedText Arg1:}{Placeholder (int)}{HorizontalSpace }{TypedText OtherArg:}{Placeholder (id)} 216// CHECK-CC8: ObjCInstanceMethodDecl:{ResultType int}{Informative Method:}{TypedText SomeArg:}{Placeholder (int)}{HorizontalSpace }{TypedText OtherArg:}{Placeholder (id)} 217// CHECK-CC8-NOT: ObjCInstanceMethodDecl:{ResultType int}{Informative Method:}{TypedText } 218// RUN: c-index-test -code-completion-at=%s:95:24 %s | FileCheck -check-prefix=CHECK-CC9 %s 219// CHECK-CC9: ObjCInstanceMethodDecl:{ResultType int}{Informative Method:}{Informative Arg1:}{TypedText Arg2:}{Placeholder (int)} 220// CHECK-CC9: ObjCInstanceMethodDecl:{ResultType int}{Informative Method:}{Informative Arg1:}{TypedText OtherArg:}{Placeholder (id)} 221// RUN: c-index-test -code-completion-at=%s:61:11 %s | FileCheck -check-prefix=CHECK-CCA %s 222// CHECK-CCA: TypedefDecl:{TypedText Class} 223// CHECK-CCA-NEXT: ObjCInterfaceDecl:{TypedText Foo} 224// CHECK-CCA-NOT: FunctionDecl:{ResultType void}{TypedText func}{LeftParen (}{RightParen )} 225// CHECK-CCA:FunctionDecl:{ResultType MyClass *}{TypedText getMyClass}{LeftParen (}{RightParen )} 226// CHECK-CCA: TypedefDecl:{TypedText id} 227// CHECK-CCA: ObjCInterfaceDecl:{TypedText MyClass} 228// CHECK-CCA: ObjCInterfaceDecl:{TypedText MySubClass} 229// CHECK-CCA: {ResultType Class}{TypedText self} 230// CHECK-CCA: {TypedText super} 231// RUN: c-index-test -code-completion-at=%s:103:6 %s | FileCheck -check-prefix=CHECK-CCB %s 232// CHECK-CCB: ObjCInstanceMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (int), ...} 233// CHECK-CCB: ObjCInstanceMethodDecl:{ResultType int}{TypedText SentinelMethod:}{Placeholder (int), ...}{Text , nil} 234// RUN: c-index-test -code-completion-at=%s:116:14 %s | FileCheck -check-prefix=CHECK-CCC %s 235// CHECK-CCC: ObjCClassMethodDecl:{ResultType int}{TypedText Method} 236// CHECK-CCC: ObjCClassMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (int)} 237// CHECK-CCC: ObjCClassMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (float)}{HorizontalSpace }{TypedText Arg1:}{Placeholder (int)}{HorizontalSpace }{TypedText Arg2:}{Placeholder (int)} 238// CHECK-CCC: ObjCClassMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (float)}{HorizontalSpace }{TypedText Arg1:}{Placeholder (int)}{HorizontalSpace }{TypedText OtherArg:}{Placeholder (id)} 239// CHECK-CCC: ObjCClassMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (float)}{HorizontalSpace }{TypedText SomeArg:}{Placeholder (int)}{HorizontalSpace }{TypedText OtherArg:}{Placeholder (id)} 240// CHECK-CCC: ObjCClassMethodDecl:{ResultType int}{TypedText OtherMethod:}{Placeholder (float)}{HorizontalSpace }{TypedText Arg1:}{Placeholder (int)}{HorizontalSpace }{TypedText Arg2:}{Placeholder (int)} 241// RUN: c-index-test -code-completion-at=%s:116:23 %s | FileCheck -check-prefix=CHECK-CCD %s 242// CHECK-CCD: ObjCClassMethodDecl:{ResultType int}{Informative Method:}{TypedText Arg1:}{Placeholder (int)}{HorizontalSpace }{TypedText Arg2:}{Placeholder (int)} 243// CHECK-CCD: ObjCClassMethodDecl:{ResultType int}{Informative Method:}{TypedText Arg1:}{Placeholder (int)}{HorizontalSpace }{TypedText OtherArg:}{Placeholder (id)} 244// CHECK-CCD: ObjCClassMethodDecl:{ResultType int}{Informative Method:}{TypedText SomeArg:}{Placeholder (int)}{HorizontalSpace }{TypedText OtherArg:}{Placeholder (id)} 245// CHECK-CCD-NOT: ObjCClassMethodDecl:{ResultType int}{Informative Method:}{TypedText } 246// RUN: c-index-test -code-completion-at=%s:116:30 %s | FileCheck -check-prefix=CHECK-CCE %s 247// CHECK-CCE: ObjCClassMethodDecl:{ResultType int}{Informative Method:}{Informative Arg1:}{TypedText Arg2:}{Placeholder (int)} 248// CHECK-CCE: ObjCClassMethodDecl:{ResultType int}{Informative Method:}{Informative Arg1:}{TypedText OtherArg:}{Placeholder (id)} 249// RUN: c-index-test -code-completion-at=%s:61:11 %s | FileCheck -check-prefix=CHECK-CCF %s 250// CHECK-CCF: TypedefDecl:{TypedText Class} 251// CHECK-CCF: ObjCInterfaceDecl:{TypedText Foo} 252// CHECK-CCF-NOT: FunctionDecl:{ResultType void}{TypedText func}{LeftParen (}{RightParen )} 253// CHECK-CCF: TypedefDecl:{TypedText id} 254// CHECK-CCF: ObjCInterfaceDecl:{TypedText MyClass} 255// CHECK-CCF: ObjCInterfaceDecl:{TypedText MySubClass} 256// CHECK-CCF: {ResultType Class}{TypedText self} 257// CHECK-CCF: {TypedText super} 258// RUN: c-index-test -code-completion-at=%s:120:6 %s | FileCheck -check-prefix=CHECK-CCG %s 259// CHECK-CCG: ObjCInstanceMethodDecl:{ResultType id}{TypedText categoryInstanceMethod} 260// CHECK-CCG: ObjCInstanceMethodDecl:{ResultType id}{TypedText instanceMethod1} 261// CHECK-CCG: ObjCInstanceMethodDecl:{ResultType int}{TypedText Method} 262// CHECK-CCG: ObjCInstanceMethodDecl:{ResultType int}{TypedText MyInstMethod:}{Placeholder (id)}{HorizontalSpace }{TypedText second:}{Placeholder (id)} 263// CHECK-CCG: ObjCInstanceMethodDecl:{ResultType int}{TypedText MyPrivateInstMethod} 264// CHECK-CCG: ObjCInstanceMethodDecl:{ResultType int}{TypedText MySubInstMethod} 265// CHECK-CCG: ObjCInstanceMethodDecl:{ResultType id}{TypedText protocolInstanceMethod:}{Placeholder (int)} 266// CHECK-CCG: ObjCInstanceMethodDecl:{ResultType int}{TypedText secondProtocolInstanceMethod} 267// RUN: c-index-test -code-completion-at=%s:121:14 %s | FileCheck -check-prefix=CHECK-CCG %s 268// RUN: c-index-test -code-completion-at=%s:122:7 %s | FileCheck -check-prefix=CHECK-CCH %s 269// CHECK-CCH: ObjCClassMethodDecl:{ResultType id}{TypedText categoryClassMethod} 270// CHECK-CCH: ObjCClassMethodDecl:{ResultType int}{TypedText classMethod1:}{Placeholder (id)}{HorizontalSpace }{TypedText withKeyword:}{Placeholder (int)} 271// CHECK-CCH: ObjCClassMethodDecl:{ResultType void}{TypedText classMethod2} 272// CHECK-CCH: ObjCClassMethodDecl:{ResultType int}{TypedText Method} 273// CHECK-CCH: ObjCClassMethodDecl:{ResultType int}{TypedText Method:}{Placeholder (int)} 274// CHECK-CCH: ObjCClassMethodDecl:{ResultType int}{TypedText MyClassMethod:}{Placeholder (id)} 275// CHECK-CCH: ObjCClassMethodDecl:{ResultType int}{TypedText MyPrivateMethod} 276// CHECK-CCH: ObjCClassMethodDecl:{ResultType int}{TypedText MySubClassMethod} 277// CHECK-CCH: ObjCClassMethodDecl:{ResultType int}{TypedText MySubPrivateMethod} 278// CHECK-CCH: ObjCClassMethodDecl:{ResultType id}{TypedText new} 279// CHECK-CCH: ObjCClassMethodDecl:{ResultType int}{TypedText OtherMethod:}{Placeholder (float)}{HorizontalSpace }{TypedText Arg1:}{Placeholder (int)}{HorizontalSpace }{TypedText Arg2:}{Placeholder (int)} 280// CHECK-CCH: ObjCClassMethodDecl:{ResultType id}{TypedText protocolClassMethod} 281// RUN: c-index-test -code-completion-at=%s:134:6 %s | FileCheck -check-prefix=CHECK-CCI %s 282// CHECK-CCI: ObjCInstanceMethodDecl:{ResultType void}{TypedText method1} (37) 283// CHECK-CCI: ObjCInstanceMethodDecl:{ResultType void}{TypedText method2} (35) 284 285// RUN: c-index-test -code-completion-at=%s:150:5 %s | FileCheck -check-prefix=CHECK-REDUNDANT %s 286// CHECK-REDUNDANT: ObjCInstanceMethodDecl:{ResultType void}{TypedText method2} (35) 287// CHECK-REDUNDANT-NOT: ObjCInstanceMethodDecl:{ResultType void}{TypedText method2} 288// CHECK-REDUNDANT: ObjCInstanceMethodDecl:{ResultType void}{TypedText method3} (35) 289 290// RUN: c-index-test -code-completion-at=%s:170:16 %s | FileCheck -check-prefix=CHECK-CLASS-RESULT %s 291// CHECK-CLASS-RESULT: ObjCClassMethodDecl:{ResultType void}{TypedText class_method3} (35) 292// CHECK-CLASS-RESULT: ObjCClassMethodDecl:{ResultType void}{TypedText class_method4} (35) 293 294// RUN: c-index-test -code-completion-at=%s:181:4 %s | FileCheck -check-prefix=CHECK-BLOCK-RECEIVER %s 295// CHECK-BLOCK-RECEIVER: ObjCInterfaceDecl:{TypedText A} (50) 296// CHECK-BLOCK-RECEIVER: ObjCInterfaceDecl:{TypedText B} (50) 297// CHECK-BLOCK-RECEIVER: ParmDecl:{ResultType A *(^)(int)}{TypedText block1} (34) 298// CHECK-BLOCK-RECEIVER-NEXT: ParmDecl:{ResultType id (^)(int)}{TypedText block3} (34) 299 300// Test code completion with a missing opening bracket: 301// RUN: c-index-test -code-completion-at=%s:135:5 %s | FileCheck -check-prefix=CHECK-CCI %s 302// RUN: c-index-test -code-completion-at=%s:139:7 %s | FileCheck -check-prefix=CHECK-CC7 %s 303// RUN: c-index-test -code-completion-at=%s:139:16 %s | FileCheck -check-prefix=CHECK-CC8 %s 304// RUN: c-index-test -code-completion-at=%s:139:23 %s | FileCheck -check-prefix=CHECK-CC9 %s 305 306// RUN: c-index-test -code-completion-at=%s:140:14 %s | FileCheck -check-prefix=CHECK-CCC %s 307// RUN: c-index-test -code-completion-at=%s:140:23 %s | FileCheck -check-prefix=CHECK-CCD %s 308// RUN: c-index-test -code-completion-at=%s:140:30 %s | FileCheck -check-prefix=CHECK-CCE %s 309// RUN: c-index-test -code-completion-at=%s:141:14 %s | FileCheck -check-prefix=CHECK-CCC %s 310// RUN: c-index-test -code-completion-at=%s:141:23 %s | FileCheck -check-prefix=CHECK-CCD %s 311// RUN: c-index-test -code-completion-at=%s:141:30 %s | FileCheck -check-prefix=CHECK-CCE %s 312 313// RUN: c-index-test -code-completion-at=%s:175:12 %s | FileCheck -check-prefix=CHECK-CLASS-RESULT %s 314