]> granicus.if.org Git - clang/commitdiff
[libclang] When pointing at an objc property don't return a cursor that points at the
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 10 Aug 2011 21:12:04 +0000 (21:12 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 10 Aug 2011 21:12:04 +0000 (21:12 +0000)
synthesized method for the property. rdar://9771715

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

test/Index/get-cursor.m [new file with mode: 0644]
tools/libclang/CIndex.cpp

diff --git a/test/Index/get-cursor.m b/test/Index/get-cursor.m
new file mode 100644 (file)
index 0000000..9932605
--- /dev/null
@@ -0,0 +1,11 @@
+// Test is line- and column-sensitive. Run lines are below.
+
+@interface rdar9771715
+@property (readonly) int foo1;
+@property (readwrite) int foo2;
+@end
+
+// RUN: c-index-test -cursor-at=%s:4:28 %s | FileCheck -check-prefix=CHECK-PROP1 %s
+// RUN: c-index-test -cursor-at=%s:5:28 %s | FileCheck -check-prefix=CHECK-PROP2 %s
+// CHECK-PROP1: ObjCPropertyDecl=foo1:4:26
+// CHECK-PROP2: ObjCPropertyDecl=foo2:5:27
index 829649a7795c98eb0f38440f701e2ab2e1edba59..875cb47a99ce0b44ddb03b7c1f5a334ba779515f 100644 (file)
@@ -3471,6 +3471,13 @@ enum CXChildVisitResult GetCursorVisitor(CXCursor cursor,
                                          CXClientData client_data) {
   GetCursorData *Data = static_cast<GetCursorData *>(client_data);
   CXCursor *BestCursor = &Data->BestCursor;
+  
+  if (clang_isDeclaration(cursor.kind)) {
+    // Avoid having the synthesized methods override the property decls.
+    if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(getCursorDecl(cursor)))
+      if (MD->isSynthesized())
+        return CXChildVisit_Break;
+  }
 
   if (clang_isExpression(cursor.kind) &&
       clang_isDeclaration(BestCursor->kind)) {