[clang-tidy] Migrate objc-super-self to use isDerivedFrom 🚛

Summary:
This migrates objc-super-self to `isDerivedFrom` as it now supports
matching Objective-C interface declarations.

Test Notes:
Ran clang tools tests.

Reviewers: aaron.ballman, gribozavr

Reviewed By: aaron.ballman

Subscribers: xazax.hun, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D66270

llvm-svn: 369081
This commit is contained in:
Stephane Moore 2019-08-16 02:27:58 +00:00
parent ee96499a42
commit a53cce943d
1 changed files with 17 additions and 30 deletions

View File

@ -35,38 +35,25 @@ AST_MATCHER(ObjCMethodDecl, isInitializer) {
return Node.getMethodFamily() == OMF_init;
}
/// \brief Matches Objective-C implementations of classes that directly or
/// indirectly have a superclass matching \c InterfaceDecl.
/// \brief Matches Objective-C implementations with interfaces that match
/// \c Base.
///
/// Note that a class is not considered to be a subclass of itself.
///
/// Example matches implementation declarations for Y and Z.
/// (matcher = objcInterfaceDecl(isSubclassOf(hasName("X"))))
/// Example matches implementation declarations for X.
/// (matcher = objcImplementationDecl(hasInterface(hasName("X"))))
/// \code
/// @interface X
/// @end
/// @interface Y : X
/// @implementation X
/// @end
/// @implementation Y // directly derived
/// @end
/// @interface Z : Y
/// @end
/// @implementation Z // indirectly derived
/// @interface Y
// @end
/// @implementation Y
/// @end
/// \endcode
AST_MATCHER_P(ObjCImplementationDecl, isSubclassOf,
ast_matchers::internal::Matcher<ObjCInterfaceDecl>,
InterfaceDecl) {
// Check if any of the superclasses of the class match.
for (const ObjCInterfaceDecl *SuperClass =
Node.getClassInterface()->getSuperClass();
SuperClass != nullptr; SuperClass = SuperClass->getSuperClass()) {
if (InterfaceDecl.matches(*SuperClass, Finder, Builder))
return true;
}
// No matches found.
return false;
AST_MATCHER_P(ObjCImplementationDecl, hasInterface,
ast_matchers::internal::Matcher<ObjCInterfaceDecl>, Base) {
const ObjCInterfaceDecl *InterfaceDecl = Node.getClassInterface();
return Base.matches(*InterfaceDecl, Finder, Builder);
}
/// \brief Matches Objective-C message expressions where the receiver is the
@ -93,11 +80,11 @@ void SuperSelfCheck::registerMatchers(MatchFinder *Finder) {
return;
Finder->addMatcher(
objcMessageExpr(
hasSelector("self"), isMessagingSuperInstance(),
hasAncestor(objcMethodDecl(isInitializer(),
hasDeclContext(objcImplementationDecl(
isSubclassOf(hasName("NSObject")))))))
objcMessageExpr(hasSelector("self"), isMessagingSuperInstance(),
hasAncestor(objcMethodDecl(
isInitializer(),
hasDeclContext(objcImplementationDecl(hasInterface(
isDerivedFrom(hasName("NSObject"))))))))
.bind("message"),
this);
}