[PATCH] D25436: [CodeCompletion] Improve completion for properties declared in Objective-C protocols

2016-10-12 Thread Alex Lorenz via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284007: [CodeCompletion] Show protocol properties that are 
accessed through qualified id (authored by arphaman).

Changed prior to commit:
  https://reviews.llvm.org/D25436?vs=74227=74364#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25436

Files:
  cfe/trunk/lib/Sema/SemaCodeComplete.cpp
  cfe/trunk/test/CodeCompletion/objc-protocol-member-access.m


Index: cfe/trunk/test/CodeCompletion/objc-protocol-member-access.m
===
--- cfe/trunk/test/CodeCompletion/objc-protocol-member-access.m
+++ cfe/trunk/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.
+
+@protocol Bar
+@property (readonly) int bar;
+@end
+
+@protocol Foo 
+
+@property (nonatomic, readonly) int foo;
+- (void)foobar: (int)x;
+
+@end
+
+int getFoo(id object) {
+  id modelObject = (id)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: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
===
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp
@@ -3720,20 +3720,21 @@
   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()->quals())
   AddObjCProperties(CCContext, I, true, /*AllowNullaryMethods=*/true,
 CurContext, AddedProperties, Results);
   } else if ((IsArrow && BaseType->isObjCObjectPointerType()) ||


Index: cfe/trunk/test/CodeCompletion/objc-protocol-member-access.m
===
--- cfe/trunk/test/CodeCompletion/objc-protocol-member-access.m
+++ cfe/trunk/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.
+
+@protocol Bar
+@property (readonly) int bar;
+@end
+
+@protocol Foo 
+
+@property (nonatomic, readonly) int foo;
+- (void)foobar: (int)x;
+
+@end
+
+int getFoo(id object) {
+  id modelObject = (id)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: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
===
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp
@@ -3720,20 +3720,21 @@
   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,
+

[PATCH] D25436: [CodeCompletion] Improve completion for properties declared in Objective-C protocols

2016-10-11 Thread Manman Ren via cfe-commits
manmanren accepted this revision.
manmanren added a comment.
This revision is now accepted and ready to land.

LGTM.

Manman


Repository:
  rL LLVM

https://reviews.llvm.org/D25436



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25436: [CodeCompletion] Improve completion for properties declared in Objective-C protocols

2016-10-11 Thread Alex Lorenz via cfe-commits
arphaman added inline comments.



Comment at: lib/Sema/SemaCodeComplete.cpp:3723
 }
   } else if (!IsArrow && BaseType->getAsObjCInterfacePointerType()) {
 // Objective-C property reference.

manmanren wrote:
> I feel like the added logic belongs to here :] Both handle property reference.
> 
> The clause here handles ObjCObjectPointerType that is based on an 
> ObjCInterfaceType. We need to handle the case where the base type is "id".
> 
> What do you think?
Yes, that makes sense. I updated the patch to handle properties in both the 
interface and qualified IDs in this body of code.


Repository:
  rL LLVM

https://reviews.llvm.org/D25436



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25436: [CodeCompletion] Improve completion for properties declared in Objective-C protocols

2016-10-11 Thread Alex Lorenz via cfe-commits
arphaman updated this revision to Diff 74227.
arphaman marked an inline comment as done.
arphaman added a comment.

The updated patch handles protocol properties together with the interface 
properties.


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.
+
+@protocol Bar
+@property (readonly) int bar;
+@end
+
+@protocol Foo 
+
+@property (nonatomic, readonly) int foo;
+- (void)foobar: (int)x;
+
+@end
+
+int getFoo(id object) {
+  id modelObject = (id)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
@@ -3720,20 +3720,21 @@
   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()->quals())
   AddObjCProperties(CCContext, I, true, /*AllowNullaryMethods=*/true,
 CurContext, AddedProperties, Results);
   } else if ((IsArrow && BaseType->isObjCObjectPointerType()) ||


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.
+
+@protocol Bar
+@property (readonly) int bar;
+@end
+
+@protocol Foo 
+
+@property (nonatomic, readonly) int foo;
+- (void)foobar: (int)x;
+
+@end
+
+int getFoo(id object) {
+  id modelObject = (id)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
@@ -3720,20 +3720,21 @@
   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()->quals())
   AddObjCProperties(CCContext, I, true, 

[PATCH] D25436: [CodeCompletion] Improve completion for properties declared in Objective-C protocols

2016-10-10 Thread Manman Ren via cfe-commits
manmanren added a comment.

Thanks for working on this!
Manman




Comment at: lib/Sema/SemaCodeComplete.cpp:3723
 }
   } else if (!IsArrow && BaseType->getAsObjCInterfacePointerType()) {
 // Objective-C property reference.

I feel like the added logic belongs to here :] Both handle property reference.

The clause here handles ObjCObjectPointerType that is based on an 
ObjCInterfaceType. We need to handle the case where the base type is "id".

What do you think?



Comment at: lib/Sema/SemaCodeComplete.cpp:3756
 }
+  } else if (const ObjCObjectPointerType *ObjCPtr =
+ BaseType->getAs()) {

Can we use "auto" here?


Repository:
  rL LLVM

https://reviews.llvm.org/D25436



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25436: [CodeCompletion] Improve completion for properties declared in Objective-C protocols

2016-10-10 Thread Alex Lorenz via cfe-commits
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.
+
+@protocol Bar
+@property (readonly) int bar;
+@end
+
+@protocol Foo 
+
+@property (nonatomic, readonly) int foo;
+- (void)foobar: (int)x;
+
+@end
+
+int getFoo(id object) {
+  id modelObject = (id)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()) {
+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?


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.
+
+@protocol Bar
+@property (readonly) int bar;
+@end
+
+@protocol Foo 
+
+@property (nonatomic, readonly) int foo;
+- (void)foobar: (int)x;
+
+@end
+
+int getFoo(id object) {
+  id modelObject = (id)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()) {
+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?
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits