[PATCH] D25436: [CodeCompletion] Improve completion for properties declared in Objective-C protocols
Alex Lorenz via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 10 09:39:38 PDT 2016
arphaman created this revision.
arphaman added reviewers: manmanren, doug.gregor.
arphaman added a subscriber: cfe-commits.
arphaman set the repository for this revision to rL LLVM.
This patch 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.
Repository:
rL LLVM
https://reviews.llvm.org/D25436
Files:
lib/Sema/SemaCodeComplete.cpp
test/CodeCompletion/objc-protocol-member-access.m
Index: test/CodeCompletion/objc-protocol-member-access.m
===================================================================
--- /dev/null
+++ test/CodeCompletion/objc-protocol-member-access.m
@@ -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
Index: lib/Sema/SemaCodeComplete.cpp
===================================================================
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -3753,6 +3753,19 @@
LookupVisibleDecls(Class, LookupMemberName, Consumer,
CodeCompleter->includeGlobals());
}
+ } else if (const ObjCObjectPointerType *ObjCPtr =
+ BaseType->getAs<ObjCObjectPointerType>()) {
+ if (const ObjCObjectType *ObjCObj = ObjCPtr->getObjectType()) {
+ if (!IsArrow && ObjCObj->isObjCQualifiedId()) {
+ AddedPropertiesSet AddedProperties;
+ // Add properties from the protocols in a qualified id.
+ for (ObjCProtocolDecl *P : ObjCObj->quals()) {
+ AddObjCProperties(CCContext, P, /*AllowCategories=*/true,
+ /*AllowNullaryMethods=*/true, CurContext,
+ AddedProperties, Results);
+ }
+ }
+ }
}
// FIXME: How do we cope with isa?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25436.74137.patch
Type: text/x-patch
Size: 1741 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161010/94c65186/attachment.bin>
More information about the cfe-commits
mailing list