]> granicus.if.org Git - clang/commitdiff
[CodeCompletion] Show protocol properties that are accessed through qualified id
authorAlex Lorenz <arphaman@gmail.com>
Wed, 12 Oct 2016 11:40:15 +0000 (11:40 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Wed, 12 Oct 2016 11:40:15 +0000 (11:40 +0000)
This commit improves code completion for properties that are declared in
Objective-C protocols by making sure that properties show up in completions
when they are accessed through a qualified id.

rdar://24426041

Differential Revision: https://reviews.llvm.org/D25436

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

lib/Sema/SemaCodeComplete.cpp
test/CodeCompletion/objc-protocol-member-access.m [new file with mode: 0644]

index 36babc4bc0cd6a8d2d1b5eba73b757fd0187322e..d235479e948c1d4d32eda5337cea32bdf3599a9b 100644 (file)
@@ -3720,20 +3720,21 @@ void Sema::CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base,
           Results.AddResult(Result("template"));
       }
     }
-  } else if (!IsArrow && BaseType->getAsObjCInterfacePointerType()) {
+  } else if (!IsArrow && BaseType->isObjCObjectPointerType()) {
     // Objective-C property reference.
     AddedPropertiesSet AddedProperties;
-    
-    // Add property results based on our interface.
-    const ObjCObjectPointerType *ObjCPtr
-      = BaseType->getAsObjCInterfacePointerType();
-    assert(ObjCPtr && "Non-NULL pointer guaranteed above!");
-    AddObjCProperties(CCContext, ObjCPtr->getInterfaceDecl(), true,
-                      /*AllowNullaryMethods=*/true, CurContext, 
-                      AddedProperties, Results);
-    
+
+    if (const ObjCObjectPointerType *ObjCPtr =
+            BaseType->getAsObjCInterfacePointerType()) {
+      // Add property results based on our interface.
+      assert(ObjCPtr && "Non-NULL pointer guaranteed above!");
+      AddObjCProperties(CCContext, ObjCPtr->getInterfaceDecl(), true,
+                        /*AllowNullaryMethods=*/true, CurContext,
+                        AddedProperties, Results);
+    }
+
     // Add properties from the protocols in a qualified interface.
-    for (auto *I : ObjCPtr->quals())
+    for (auto *I : BaseType->getAs<ObjCObjectPointerType>()->quals())
       AddObjCProperties(CCContext, I, true, /*AllowNullaryMethods=*/true,
                         CurContext, AddedProperties, Results);
   } else if ((IsArrow && BaseType->isObjCObjectPointerType()) ||
diff --git a/test/CodeCompletion/objc-protocol-member-access.m b/test/CodeCompletion/objc-protocol-member-access.m
new file mode 100644 (file)
index 0000000..0ed5538
--- /dev/null
@@ -0,0 +1,24 @@
+// Note: the run lines follow their respective tests, since line/column
+// matter in this test.
+
+@protocol Bar
+@property (readonly) int bar;
+@end
+
+@protocol Foo <Bar>
+
+@property (nonatomic, readonly) int foo;
+- (void)foobar: (int)x;
+
+@end
+
+int getFoo(id object) {
+  id<Foo> modelObject = (id<Foo>)object;
+  int foo = modelObject.;
+  return foo;
+}
+
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:17:25 %s -o - | FileCheck %s
+// CHECK: bar : [#int#]bar
+// CHECK: foo : [#int#]foo
+// CHECK-NOT: foobar