Skip to content

Commit a169f37

Browse files
committed
[NFC] Expose extension category name accessor
1 parent 1600bee commit a169f37

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
@@ -1633,6 +1633,10 @@ class ExtensionDecl final : public GenericContext, public Decl,
16331633
/// \c isObjCImplementation() returns \c true.
16341634
Optional<Identifier> getCategoryNameForObjCImplementation() const;
16351635

1636+
/// If this extension represents an imported Objective-C category, returns the
1637+
/// category's name. Otherwise returns the empty identifier.
1638+
Identifier getObjCCategoryName() const;
1639+
16361640
// Implement isa/cast/dyncast/etc.
16371641
static bool classof(const Decl *D) {
16381642
return D->getKind() == DeclKind::Extension;

lib/ClangImporter/ClangImporter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5132,20 +5132,20 @@ findImplsGivenInterface(ClassDecl *classDecl, Identifier categoryName) {
51325132
return impls;
51335133
}
51345134

5135-
static Identifier getCategoryName(ExtensionDecl *ext) {
5135+
Identifier ExtensionDecl::getObjCCategoryName() const {
51365136
// Could it be an imported category?
5137-
if (!ext || !ext->hasClangNode())
5137+
if (!hasClangNode())
51385138
// Nope, not imported.
51395139
return Identifier();
51405140

5141-
auto category = dyn_cast<clang::ObjCCategoryDecl>(ext->getClangDecl());
5141+
auto category = dyn_cast<clang::ObjCCategoryDecl>(getClangDecl());
51425142
if (!category)
51435143
// Nope, not a category.
51445144
return Identifier();
51455145

51465146
// We'll look for an implementation with this category name.
51475147
auto clangCategoryName = category->getName();
5148-
return ext->getASTContext().getIdentifier(clangCategoryName);
5148+
return getASTContext().getIdentifier(clangCategoryName);
51495149
}
51505150

51515151
static IterableDeclContext *
@@ -5195,7 +5195,7 @@ findContextInterfaceAndImplementation(DeclContext *dc) {
51955195

51965196
// Is this an imported category? If so, extract its name so we can look for
51975197
// implementations of that category.
5198-
categoryName = getCategoryName(ext);
5198+
categoryName = ext->getObjCCategoryName();
51995199
if (categoryName.empty())
52005200
return {};
52015201

0 commit comments

Comments
 (0)