]> granicus.if.org Git - clang/commitdiff
When trying to provide a code completion item for a call to "super" in
authorDouglas Gregor <dgregor@apple.com>
Wed, 16 Feb 2011 00:51:18 +0000 (00:51 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 16 Feb 2011 00:51:18 +0000 (00:51 +0000)
Objective-C, also look in the categories and class extensions of our
superclasses. Fixes <rdar://problem/8853540>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125628 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaCodeComplete.cpp
test/Index/complete-super.m

index 3a07ef6783ea90a00e3c08d3fd6464c3d49f9046..d92b9fe71cd1e528a9996347c7361c0779edd59a 100644 (file)
@@ -4478,10 +4478,21 @@ static ObjCMethodDecl *AddSuperSendCompletion(Sema &S, bool NeedSuperKeyword,
   
   // Try to find a superclass method with the same selector.
   ObjCMethodDecl *SuperMethod = 0;
-  while ((Class = Class->getSuperClass()) && !SuperMethod)
+  while ((Class = Class->getSuperClass()) && !SuperMethod) {
+    // Check in the class
     SuperMethod = Class->getMethod(CurMethod->getSelector(), 
                                    CurMethod->isInstanceMethod());
 
+    // Check in categories or class extensions.
+    if (!SuperMethod) {
+      for (ObjCCategoryDecl *Category = Class->getCategoryList(); Category;
+           Category = Category->getNextClassCategory())
+        if ((SuperMethod = Category->getMethod(CurMethod->getSelector(), 
+                                               CurMethod->isInstanceMethod())))
+          break;
+    }
+  }
+
   if (!SuperMethod)
     return 0;
   
index 7772a72119757737da0c9fd75c8c1d7a7495394c..6c2daa8082067cb863b91bb5e0d8678ba72314f6 100644 (file)
@@ -26,6 +26,19 @@ typedef int Bool;
 }
 @end
 
+@interface A (Cat)
+- (void)multiply:(int)x by:(int)y;
+@end
+
+@interface C : A
+@end
+
+@implementation C
+- (void)multiply:(int)a by:(int)b {
+  [super multiply:a by:b];
+}
+@end
+
 // Check "super" completion as a message receiver.
 // RUN: c-index-test -code-completion-at=%s:20:4 %s | FileCheck -check-prefix=CHECK-ADD-RECEIVER %s
 // CHECK-ADD-RECEIVER: ObjCInstanceMethodDecl:{ResultType void}{TypedText super}{HorizontalSpace  }{Text add:}{Placeholder a}{HorizontalSpace  }{Text to:}{Placeholder b} (20)
@@ -59,3 +72,10 @@ typedef int Bool;
 // RUN: c-index-test -code-completion-at=%s:25:10 %s | FileCheck -check-prefix=CHECK-SELECTOR-SELECTOR %s
 // RUN: c-index-test -code-completion-at=%s:25:28 %s | FileCheck -check-prefix=CHECK-SELECTOR-FIRST %s
 // RUN: c-index-test -code-completion-at=%s:25:37 %s | FileCheck -check-prefix=CHECK-SELECTOR-SECOND %s
+
+// Check "super" completion for a method declared in a category.
+// RUN: c-index-test -code-completion-at=%s:38:10 %s | FileCheck -check-prefix=CHECK-IN-CATEGORY %s
+// CHECK-IN-CATEGORY: ObjCInstanceMethodDecl:{ResultType void}{TypedText add:}{Placeholder (int)}{HorizontalSpace  }{TypedText to:}{Placeholder (int)} (35)
+// CHECK-IN-CATEGORY: ObjCInstanceMethodDecl:{ResultType void}{TypedText last} (35)
+// CHECK-IN-CATEGORY: ObjCInstanceMethodDecl:{ResultType void}{TypedText multiply:}{Placeholder a}{HorizontalSpace  }{Text by:}{Placeholder b} (20)
+