r284007 - [CodeCompletion] Show protocol properties that are accessed through qualified id
Alex Lorenz via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 12 04:40:16 PDT 2016
Author: arphaman
Date: Wed Oct 12 06:40:15 2016
New Revision: 284007
URL: http://llvm.org/viewvc/llvm-project?rev=284007&view=rev
Log:
[CodeCompletion] Show protocol properties that are accessed through qualified id
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
Added:
cfe/trunk/test/CodeCompletion/objc-protocol-member-access.m
Modified:
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=284007&r1=284006&r2=284007&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Wed Oct 12 06:40:15 2016
@@ -3720,20 +3720,21 @@ void Sema::CodeCompleteMemberReferenceEx
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()) ||
Added: cfe/trunk/test/CodeCompletion/objc-protocol-member-access.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/objc-protocol-member-access.m?rev=284007&view=auto
==============================================================================
--- cfe/trunk/test/CodeCompletion/objc-protocol-member-access.m (added)
+++ cfe/trunk/test/CodeCompletion/objc-protocol-member-access.m Wed Oct 12 06:40:15 2016
@@ -0,0 +1,24 @@
+// Note: the run lines follow their respective tests, since line/column
+// matter in this test.
+
+ at protocol Bar
+ at property (readonly) int bar;
+ at end
+
+ at protocol Foo <Bar>
+
+ at property (nonatomic, readonly) int foo;
+- (void)foobar: (int)x;
+
+ at 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
More information about the cfe-commits
mailing list