diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 046b18712c38..409219a57156 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -413,7 +413,16 @@ comments::FullComment *ASTContext::getCommentForDecl( if (!RC) { if (isa(D) || isa(D)) { SmallVector Overridden; - if (const ObjCMethodDecl *OMD = dyn_cast(D)) + const ObjCMethodDecl *OMD = dyn_cast(D); + if (OMD && OMD->isPropertyAccessor()) { + if (const ObjCPropertyDecl *PDecl = OMD->findPropertyDecl()) { + if (comments::FullComment *FC = getCommentForDecl(PDecl, PP)) { + comments::FullComment *CFC = cloneFullComment(FC, D); + return CFC; + } + } + } + if (OMD) addRedeclaredMethods(OMD, Overridden); getOverriddenMethods(dyn_cast(D), Overridden); for (unsigned i = 0, e = Overridden.size(); i < e; i++) { diff --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp index 32503ad78578..816c43200a89 100644 --- a/clang/lib/AST/DeclObjC.cpp +++ b/clang/lib/AST/DeclObjC.cpp @@ -947,6 +947,11 @@ ObjCMethodDecl::findPropertyDecl(bool CheckOverrides) const { if (isPropertyAccessor()) { const ObjCContainerDecl *Container = cast(getParent()); + // If container is class extension, find its primary class. + if (const ObjCCategoryDecl *CatDecl = dyn_cast(Container)) + if (CatDecl->IsClassExtension()) + Container = CatDecl->getClassInterface(); + bool IsGetter = (NumArgs == 0); for (ObjCContainerDecl::prop_iterator I = Container->prop_begin(), diff --git a/clang/test/Index/annotate-comments-property-accessor.m b/clang/test/Index/annotate-comments-property-accessor.m new file mode 100644 index 000000000000..2bd1d0135cdd --- /dev/null +++ b/clang/test/Index/annotate-comments-property-accessor.m @@ -0,0 +1,62 @@ +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: c-index-test -test-load-source all -comments-xml-schema=%S/../../bindings/xml/comment-xml-schema.rng %s > %t/out +// RUN: FileCheck %s < %t/out +// rdar://12378879 + +// Ensure that XML we generate is not invalid. +// RUN: FileCheck %s -check-prefix=WRONG < %t/out +// WRONG-NOT: CommentXMLInvalid + +@interface AppDelegate +/** + \brief This is ReadonlyProperty +*/ +@property (readonly, getter = ReadonlyGetter) int MyProperty; +// CHECK: FullCommentAsXML=[MyPropertyc:objc(cs)AppDelegate(py)MyProperty- (int)ReadonlyGetter; This is ReadonlyProperty] + +/** + \brief This is GeneralProperty +*/ +@property int GeneralProperty; +// CHECK: FullCommentAsXML=[GeneralPropertyc:objc(cs)AppDelegate(py)GeneralProperty- (int)GeneralProperty; This is GeneralProperty] +// CHECK: FullCommentAsXML=[GeneralPropertyc:objc(cs)AppDelegate(py)GeneralProperty- (void)setGeneralProperty:(int)GeneralProperty; This is GeneralProperty] + +/** + \brief This is PropertyInPrimaryClass +*/ +@property (copy, nonatomic) id PropertyInPrimaryClass; +- (void) setThisRecord : (id)arg; +- (id) Record; +@end +// CHECK: FullCommentAsXML=[PropertyInPrimaryClassc:objc(cs)AppDelegate(py)PropertyInPrimaryClass- (id)PropertyInPrimaryClass; This is PropertyInPrimaryClass] +// CHECK: FullCommentAsXML=[PropertyInPrimaryClassc:objc(cs)AppDelegate(py)PropertyInPrimaryClass- (void)setPropertyInPrimaryClass:(id)PropertyInPrimaryClass; This is PropertyInPrimaryClass] + +@interface AppDelegate() +- (id) GetterInClassExtension; +/** + \brief This is Record +*/ +@property (copy, setter = setThisRecord:) id Record; +@end +// CHECK: FullCommentAsXML=[PropertyInClassExtensionc:objc(cs)AppDelegate(py)PropertyInClassExtension- (id)GetterInClassExtension; This is PropertyInClassExtension] + +@interface AppDelegate() +/** + \brief This is PropertyInClassExtension +*/ +@property (copy, getter = GetterInClassExtension) id PropertyInClassExtension; + +- (id) PropertyInPrimaryClass; +@end +// CHECK: FullCommentAsXML=[PropertyInClassExtensionc:objc(cs)AppDelegate(py)PropertyInClassExtension- (id)GetterInClassExtension; This is PropertyInClassExtension] +// CHECK: FullCommentAsXML=[PropertyInClassExtensionc:objc(cs)AppDelegate(py)PropertyInClassExtension- (void)setPropertyInClassExtension:(id)PropertyInClassExtension; This is PropertyInClassExtension] + +@implementation AppDelegate +- (id) PropertyInPrimaryClass { return 0; } +@end + + + + +