forked from OSchip/llvm-project
Special case ObjCPropertyDecl for printing
ObjCPropertyDecl should use the category interface as a context similar to what is done for methods. Previously category methods would be printed as `::property`; now they are printed as `Class::property`. llvm-svn: 357720
This commit is contained in:
parent
e028de43cd
commit
19d21854e9
|
@ -1531,10 +1531,16 @@ void NamedDecl::printQualifiedName(raw_ostream &OS,
|
|||
const PrintingPolicy &P) const {
|
||||
const DeclContext *Ctx = getDeclContext();
|
||||
|
||||
// For ObjC methods, look through categories and use the interface as context.
|
||||
// For ObjC methods and properties, look through categories and use the
|
||||
// interface as context.
|
||||
if (auto *MD = dyn_cast<ObjCMethodDecl>(this))
|
||||
if (auto *ID = MD->getClassInterface())
|
||||
Ctx = ID;
|
||||
if (auto *PD = dyn_cast<ObjCPropertyDecl>(this)) {
|
||||
if (auto *MD = PD->getGetterMethodDecl())
|
||||
if (auto *ID = MD->getClassInterface())
|
||||
Ctx = ID;
|
||||
}
|
||||
|
||||
if (Ctx->isFunctionOrMethod()) {
|
||||
printName(OS);
|
||||
|
|
|
@ -115,6 +115,18 @@ PrintedWrittenNamedDeclCXX11Matches(StringRef Code, StringRef DeclName,
|
|||
"input.cc");
|
||||
}
|
||||
|
||||
::testing::AssertionResult
|
||||
PrintedWrittenPropertyDeclObjCMatches(StringRef Code, StringRef DeclName,
|
||||
StringRef ExpectedPrinted) {
|
||||
std::vector<std::string> Args{"-std=c++11", "-xobjective-c++"};
|
||||
return PrintedNamedDeclMatches(Code,
|
||||
Args,
|
||||
/*SuppressUnwrittenScope*/ true,
|
||||
objcPropertyDecl(hasName(DeclName)).bind("id"),
|
||||
ExpectedPrinted,
|
||||
"input.m");
|
||||
}
|
||||
|
||||
} // unnamed namespace
|
||||
|
||||
TEST(NamedDeclPrinter, TestNamespace1) {
|
||||
|
@ -179,3 +191,31 @@ TEST(NamedDeclPrinter, TestLinkageInNamespace) {
|
|||
"A",
|
||||
"X::A"));
|
||||
}
|
||||
|
||||
TEST(NamedDeclPrinter, TestObjCClassExtension) {
|
||||
ASSERT_TRUE(PrintedWrittenPropertyDeclObjCMatches(
|
||||
R"(
|
||||
@interface Obj
|
||||
@end
|
||||
|
||||
@interface Obj ()
|
||||
@property(nonatomic) int property;
|
||||
@end
|
||||
)",
|
||||
"property",
|
||||
"Obj::property"));
|
||||
}
|
||||
|
||||
TEST(NamedDeclPrinter, TestObjCClassExtensionWithGetter) {
|
||||
ASSERT_TRUE(PrintedWrittenPropertyDeclObjCMatches(
|
||||
R"(
|
||||
@interface Obj
|
||||
@end
|
||||
|
||||
@interface Obj ()
|
||||
@property(nonatomic, getter=myPropertyGetter) int property;
|
||||
@end
|
||||
)",
|
||||
"property",
|
||||
"Obj::property"));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue