Skip to content

Commit

Permalink
Fix ObjCMethodDecl::findPropertyDecl for class properties.
Browse files Browse the repository at this point in the history
This affects code completion and a few other things; hopefully the code completion
test is sufficient to catch regressions.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@263295 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
jrose-apple committed Mar 11, 2016
1 parent d5ee7cc commit d528935
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lib/AST/DeclObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1234,23 +1234,29 @@ ObjCMethodDecl::findPropertyDecl(bool CheckOverrides) const {
if (NumArgs > 1)
return nullptr;

if (!isInstanceMethod())
return nullptr;

if (isPropertyAccessor()) {
const ObjCContainerDecl *Container = cast<ObjCContainerDecl>(getParent());
bool IsGetter = (NumArgs == 0);
bool IsInstance = isInstanceMethod();

/// Local function that attempts to find a matching property within the
/// given Objective-C container.
auto findMatchingProperty =
[&](const ObjCContainerDecl *Container) -> const ObjCPropertyDecl * {

for (const auto *I : Container->instance_properties()) {
Selector NextSel = IsGetter ? I->getGetterName()
: I->getSetterName();
if (NextSel == Sel)
return I;
if (IsInstance) {
for (const auto *I : Container->instance_properties()) {
Selector NextSel = IsGetter ? I->getGetterName()
: I->getSetterName();
if (NextSel == Sel)
return I;
}
} else {
for (const auto *I : Container->class_properties()) {
Selector NextSel = IsGetter ? I->getGetterName()
: I->getSetterName();
if (NextSel == Sel)
return I;
}
}

return nullptr;
Expand Down
25 changes: 25 additions & 0 deletions test/CodeCompletion/documentation.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Note: the run lines follow their respective tests, since line/column
// matter in this test.

@interface Base
@end

@interface Test : Base
/// Instance!
@property id instanceProp;
/// Class!
@property (class) id classProp;
@end

void test(Test *obj) {
[obj instanceProp];
[Test classProp];
}

// RUN: %clang_cc1 -fsyntax-only -code-completion-brief-comments -code-completion-at=%s:15:8 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
// CHECK-CC1: instanceProp : [#id#]instanceProp : Instance!
// CHECK-CC1: setInstanceProp: : [#void#]setInstanceProp:<#(id)#> : Instance!

// RUN: %clang_cc1 -fsyntax-only -code-completion-brief-comments -code-completion-at=%s:16:9 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
// CHECK-CC2: classProp : [#id#]classProp : Class!
// CHECK-CC2: setClassProp: : [#void#]setClassProp:<#(id)#> : Class!

0 comments on commit d528935

Please sign in to comment.