Index: docs/LibASTMatchersReference.html =================================================================== --- docs/LibASTMatchersReference.html +++ docs/LibASTMatchersReference.html @@ -337,6 +337,15 @@ +Matcher<Decl>objcCategoryDeclMatcher<ObjCCategoryDecl>... +
Matches Objective-C category declarations.
+
+Example matches Foo (Additions)
+  @interface Foo (Additions)
+  @end
+
+ + Matcher<Decl>objcInterfaceDeclMatcher<ObjCInterfaceDecl>...
Matches Objective-C interface declarations.
 
@@ -346,6 +355,50 @@
 
+Matcher<Decl>objcIvarDeclMatcher<ObjCIvarDecl>... +
Matches Objective-C instance variable declarations.
+
+Example matches _enabled
+  @implementation Foo {
+    BOOL _enabled;
+  }
+  @end
+
+ + +Matcher<Decl>objcMethodDeclMatcher<ObjCMethodDecl>... +
Matches Objective-C method declarations.
+
+Example matches both declaration and definition of -[Foo method]
+  @interface Foo
+  - (void)method;
+  @end
+
+  @implementation Foo
+  - (void)method {}
+  @end
+
+ + +Matcher<Decl>objcPropertyDeclMatcher<ObjCPropertyDecl>... +
Matches Objective-C property declarations.
+
+Example matches enabled
+  @interface Foo
+  @property BOOL enabled;
+  @end
+
+ + +Matcher<Decl>objcProtocolDeclMatcher<ObjCProtocolDecl>... +
Matches Objective-C protocol declarations.
+
+Example matches FooDelegate
+  @protocol FooDelegate
+  @end
+
+ + Matcher<Decl>parmVarDeclMatcher<ParmVarDecl>...
Matches parameter variable declarations.
 
Index: include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -1118,6 +1118,69 @@
   Decl,
   ObjCInterfaceDecl> objcInterfaceDecl;
 
+/// \brief Matches Objective-C protocol declarations.
+///
+/// Example matches FooDelegate
+/// \code
+///   @protocol FooDelegate
+///   @end
+/// \endcode
+const internal::VariadicDynCastAllOfMatcher<
+  Decl,
+  ObjCProtocolDecl> objcProtocolDecl;
+
+/// \brief Matches Objective-C category declarations.
+///
+/// Example matches Foo (Additions)
+/// \code
+///   @interface Foo (Additions)
+///   @end
+/// \endcode
+const internal::VariadicDynCastAllOfMatcher<
+  Decl,
+  ObjCCategoryDecl> objcCategoryDecl;
+
+/// \brief Matches Objective-C method declarations.
+///
+/// Example matches both declaration and definition of -[Foo method]
+/// \code
+///   @interface Foo
+///   - (void)method;
+///   @end
+///
+///   @implementation Foo
+///   - (void)method {}
+///   @end
+/// \endcode
+const internal::VariadicDynCastAllOfMatcher<
+  Decl,
+  ObjCMethodDecl> objcMethodDecl;
+
+/// \brief Matches Objective-C instance variable declarations.
+///
+/// Example matches _enabled
+/// \code
+///   @implementation Foo {
+///     BOOL _enabled;
+///   }
+///   @end
+/// \endcode
+const internal::VariadicDynCastAllOfMatcher<
+  Decl,
+  ObjCIvarDecl> objcIvarDecl;
+
+/// \brief Matches Objective-C property declarations.
+///
+/// Example matches enabled
+/// \code
+///   @interface Foo
+///   @property BOOL enabled;
+///   @end
+/// \endcode
+const internal::VariadicDynCastAllOfMatcher<
+  Decl,
+  ObjCPropertyDecl> objcPropertyDecl;
+
 /// \brief Matches expressions that introduce cleanups to be run at the end
 /// of the sub-expression's evaluation.
 ///
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===================================================================
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -360,6 +360,11 @@
   REGISTER_MATCHER(numSelectorArgs);
   REGISTER_MATCHER(ofClass);
   REGISTER_MATCHER(objcInterfaceDecl);
+  REGISTER_MATCHER(objcProtocolDecl);
+  REGISTER_MATCHER(objcCategoryDecl);
+  REGISTER_MATCHER(objcMethodDecl);
+  REGISTER_MATCHER(objcIvarDecl);
+  REGISTER_MATCHER(objcPropertyDecl);
   REGISTER_MATCHER(objcMessageExpr);
   REGISTER_MATCHER(objcObjectPointerType);
   REGISTER_MATCHER(on);
Index: unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===================================================================
--- unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1498,7 +1498,9 @@
   // don't find ObjCMessageExpr where none are present
   EXPECT_TRUE(notMatchesObjC("", objcMessageExpr(anything())));
 
-  std::string Objc1String =
+  std::string ObjCString =
+    "#pragma clang diagnostic ignored \"-Wobjc-root-class\"\n"
+    "#pragma clang diagnostic ignored \"-Wobjc-method-access\"\n"
     "@interface Str "
       " - (Str *)uppercaseString:(Str *)str;"
       "@end "
@@ -1513,32 +1515,73 @@
       "} "
       "@end ";
   EXPECT_TRUE(matchesObjC(
-    Objc1String,
+    ObjCString,
     objcMessageExpr(anything())));
   EXPECT_TRUE(matchesObjC(
-    Objc1String,
+    ObjCString,
     objcMessageExpr(hasSelector("contents"))));
   EXPECT_TRUE(matchesObjC(
-    Objc1String,
+    ObjCString,
     objcMessageExpr(matchesSelector("cont*"))));
   EXPECT_FALSE(matchesObjC(
-    Objc1String,
+    ObjCString,
     objcMessageExpr(matchesSelector("?cont*"))));
   EXPECT_TRUE(notMatchesObjC(
-    Objc1String,
+    ObjCString,
     objcMessageExpr(hasSelector("contents"), hasNullSelector())));
   EXPECT_TRUE(matchesObjC(
-    Objc1String,
+    ObjCString,
     objcMessageExpr(hasSelector("contents"), hasUnarySelector())));
   EXPECT_TRUE(matchesObjC(
-    Objc1String,
+    ObjCString,
     objcMessageExpr(hasSelector("contents"), numSelectorArgs(0))));
   EXPECT_TRUE(matchesObjC(
-    Objc1String,
+    ObjCString,
     objcMessageExpr(matchesSelector("uppercase*"),
                     argumentCountIs(0)
     )));
 }
 
+TEST(ObjCDeclMacher, CoreDecls) {
+  std::string ObjCString =
+    "#pragma clang diagnostic ignored \"-Wobjc-root-class\"\n"
+    "@protocol Proto "
+    "- (void)protoDidThing; "
+    "@end "
+    "@interface Thing "
+    "@property int enabled; "
+    "@end "
+    "@interface Thing (ABC) "
+    "- (void)abc_doThing; "
+    "@end "
+    "@implementation Thing "
+    "{ id _ivar; } "
+    "- (void)anything {} "
+    "@end "
+    ;
+
+  EXPECT_TRUE(matchesObjC(
+    ObjCString,
+    objcProtocolDecl(hasName("Proto"))));
+  EXPECT_TRUE(matchesObjC(
+    ObjCString,
+    objcCategoryDecl(hasName("ABC"))));
+  EXPECT_TRUE(matchesObjC(
+    ObjCString,
+    objcMethodDecl(hasName("protoDidThing"))));
+  EXPECT_TRUE(matchesObjC(
+    ObjCString,
+    objcMethodDecl(hasName("abc_doThing"))));
+  EXPECT_TRUE(matchesObjC(
+    ObjCString,
+    objcMethodDecl(hasName("anything"))));
+  EXPECT_TRUE(matchesObjC(
+    ObjCString,
+    objcIvarDecl(hasName("_ivar"))));
+  EXPECT_TRUE(matchesObjC(
+    ObjCString,
+    objcPropertyDecl(hasName("enabled"))));
+}
+
 } // namespace ast_matchers
 } // namespace clang
Index: unittests/ASTMatchers/ASTMatchersTest.h
===================================================================
--- unittests/ASTMatchers/ASTMatchersTest.h
+++ unittests/ASTMatchers/ASTMatchersTest.h
@@ -120,7 +120,7 @@
                                      const T &AMatcher) {
   return matchesConditionally(
     Code, AMatcher, true,
-    "", FileContentMappings(), "input.m");
+    "-fobjc-runtime=macosx", FileContentMappings(), "input.m");
 }
 
 template 
@@ -148,7 +148,7 @@
                                      const T &AMatcher) {
   return matchesConditionally(
     Code, AMatcher, false,
-    "", FileContentMappings(), "input.m");
+    "-fobjc-runtime=macosx", FileContentMappings(), "input.m");
 }