Skip to content

Commit e09d02e

Browse files
committed
[NFC] Expose extension category name accessor
1 parent 88c28cd commit e09d02e

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

include/swift/AST/Decl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,6 +1637,10 @@ class ExtensionDecl final : public GenericContext, public Decl,
16371637
/// \c isObjCImplementation() returns \c true.
16381638
Optional<Identifier> getCategoryNameForObjCImplementation() const;
16391639

1640+
/// If this extension represents an imported Objective-C category, returns the
1641+
/// category's name. Otherwise returns the empty identifier.
1642+
Identifier getObjCCategoryName() const;
1643+
16401644
// Implement isa/cast/dyncast/etc.
16411645
static bool classof(const Decl *D) {
16421646
return D->getKind() == DeclKind::Extension;

lib/ClangImporter/ClangImporter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5183,20 +5183,20 @@ findImplsGivenInterface(ClassDecl *classDecl, Identifier categoryName) {
51835183
return impls;
51845184
}
51855185

5186-
static Identifier getCategoryName(ExtensionDecl *ext) {
5186+
Identifier ExtensionDecl::getObjCCategoryName() const {
51875187
// Could it be an imported category?
5188-
if (!ext || !ext->hasClangNode())
5188+
if (!hasClangNode())
51895189
// Nope, not imported.
51905190
return Identifier();
51915191

5192-
auto category = dyn_cast<clang::ObjCCategoryDecl>(ext->getClangDecl());
5192+
auto category = dyn_cast<clang::ObjCCategoryDecl>(getClangDecl());
51935193
if (!category)
51945194
// Nope, not a category.
51955195
return Identifier();
51965196

51975197
// We'll look for an implementation with this category name.
51985198
auto clangCategoryName = category->getName();
5199-
return ext->getASTContext().getIdentifier(clangCategoryName);
5199+
return getASTContext().getIdentifier(clangCategoryName);
52005200
}
52015201

52025202
static IterableDeclContext *
@@ -5246,7 +5246,7 @@ findContextInterfaceAndImplementation(DeclContext *dc) {
52465246

52475247
// Is this an imported category? If so, extract its name so we can look for
52485248
// implementations of that category.
5249-
categoryName = getCategoryName(ext);
5249+
categoryName = ext->getObjCCategoryName();
52505250
if (categoryName.empty())
52515251
return {};
52525252

0 commit comments

Comments
 (0)