Index: clang/include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- clang/include/clang/ASTMatchers/ASTMatchers.h +++ clang/include/clang/ASTMatchers/ASTMatchers.h @@ -1515,6 +1515,15 @@ extern const internal::VariadicDynCastAllOfMatcher objcMessageExpr; +/// Matches ObjectiveC String literal expressions. +/// +/// Example matches @"abcd" +/// \code +/// NSString *s = @"abcd"; +/// \endcode +extern const internal::VariadicDynCastAllOfMatcher + objcStringLiteral; + /// Matches Objective-C interface declarations. /// /// Example matches Foo Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp =================================================================== --- clang/lib/ASTMatchers/ASTMatchersInternal.cpp +++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp @@ -917,6 +917,7 @@ const internal::VariadicDynCastAllOfMatcher cxxBoolLiteral; const internal::VariadicDynCastAllOfMatcher stringLiteral; +const internal::VariadicDynCastAllOfMatcher objcStringLiteral; const internal::VariadicDynCastAllOfMatcher characterLiteral; const internal::VariadicDynCastAllOfMatcher Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp =================================================================== --- clang/lib/ASTMatchers/Dynamic/Registry.cpp +++ clang/lib/ASTMatchers/Dynamic/Registry.cpp @@ -505,6 +505,7 @@ REGISTER_MATCHER(objcObjectPointerType); REGISTER_MATCHER(objcPropertyDecl); REGISTER_MATCHER(objcProtocolDecl); + REGISTER_MATCHER(objcStringLiteral); REGISTER_MATCHER(objcThrowStmt); REGISTER_MATCHER(objcTryStmt); REGISTER_MATCHER(ofClass); Index: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp =================================================================== --- clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp +++ clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp @@ -2352,6 +2352,26 @@ argumentCountIs(0)))); } +TEST(ASTMatchersTestObjC, ObjCStringLiteral) { + + StringRef Objc1String = "@interface NSObject " + "@end " + "@interface NSString " + "@end " + "@interface Test : NSObject " + "+ (void)someFunction:(NSString *)Desc; " + "@end " + "@implementation Test " + "+ (void)someFunction:(NSString *)Desc { " + " return; " + "} " + "- (void) foo { " + " [Test someFunction:@\"Ola!\"]; " + "}\n" + "@end "; + EXPECT_TRUE(matchesObjC(Objc1String, objcStringLiteral())); +} + TEST(ASTMatchersTestObjC, ObjCDecls) { StringRef ObjCString = "@protocol Proto " "- (void)protoDidThing; "