Index: include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- include/clang/ASTMatchers/ASTMatchers.h +++ include/clang/ASTMatchers/ASTMatchers.h @@ -3466,7 +3466,7 @@ return Node.requiresZeroInitialization(); } -/// \brief Matches the n'th parameter of a function declaration. +/// \brief Matches the n'th parameter of a function or ObjC method declaration. /// /// Given /// \code @@ -3476,9 +3476,11 @@ /// matches f(int x) {} /// with hasParameter(...) /// matching int x -AST_MATCHER_P2(FunctionDecl, hasParameter, - unsigned, N, internal::Matcher, - InnerMatcher) { +AST_POLYMORPHIC_MATCHER_P2(hasParameter, + AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, + ObjCMethodDecl), + unsigned, N, internal::Matcher, + InnerMatcher) { return (N < Node.getNumParams() && InnerMatcher.matches( *Node.getParamDecl(N), Finder, Builder)); @@ -3538,7 +3540,7 @@ return Matched; } -/// \brief Matches any parameter of a function declaration. +/// \brief Matches any parameter of a function or ObjC method declaration. /// /// Does not match the 'this' parameter of a method. /// @@ -3550,8 +3552,11 @@ /// matches f(int x, int y, int z) {} /// with hasAnyParameter(...) /// matching int y -AST_MATCHER_P(FunctionDecl, hasAnyParameter, - internal::Matcher, InnerMatcher) { +AST_POLYMORPHIC_MATCHER_P(hasAnyParameter, + AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, + ObjCMethodDecl), + internal::Matcher, + InnerMatcher) { return matchesFirstInPointerRange(InnerMatcher, Node.param_begin(), Node.param_end(), Finder, Builder); } Index: unittests/ASTMatchers/ASTMatchersTraversalTest.cpp =================================================================== --- unittests/ASTMatchers/ASTMatchersTraversalTest.cpp +++ unittests/ASTMatchers/ASTMatchersTraversalTest.cpp @@ -539,6 +539,8 @@ cxxMethodDecl(hasParameter(0, varDecl())))); EXPECT_TRUE(notMatches("class X { void x(int) {} };", cxxMethodDecl(hasParameter(0, hasName("x"))))); + EXPECT_TRUE(matches("@interface I -(void)f:(int) x; @end", + objcMethodDecl(hasParameter(0, hasName("x"))))); } TEST(HasParameter, DoesNotMatchIfIndexOutOfBounds) { @@ -568,6 +570,8 @@ EXPECT_TRUE(matches( "class Y {}; class X { void x(Y y, X x) {} };", cxxMethodDecl(hasAnyParameter(hasType(recordDecl(hasName("X"))))))); + EXPECT_TRUE(matches("@interface I -(void)f:(int) x; @end", + objcMethodDecl(hasAnyParameter(hasName("x"))))); } TEST(Returns, MatchesReturnTypes) {