aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Tooling/TransformerTest.cpp
diff options
context:
space:
mode:
authorAndy Soffer <asoffer>2020-06-30 14:35:15 +0000
committerYitzhak Mandelbaum <yitzhakm@google.com>2020-06-30 15:03:07 +0000
commit9945bd5911636e7f821ac82fdcf8fdb22126e7dc (patch)
treeef0a844e48346de35001c563f9d46c9361f6576a /clang/unittests/Tooling/TransformerTest.cpp
parentce404c8b854b18ca2aaa9529986b3eced73793a3 (diff)
downloadllvm-9945bd5911636e7f821ac82fdcf8fdb22126e7dc.zip
llvm-9945bd5911636e7f821ac82fdcf8fdb22126e7dc.tar.gz
llvm-9945bd5911636e7f821ac82fdcf8fdb22126e7dc.tar.bz2
Add Metadata to Transformer tooling
This change adds a Metadata field to ASTEdit, Edit, and AtomicChange so that edits can have associated metadata and that metadata can be constructed with Transformer-based RewriteRules. Metadata is ignored when applying edits to source, but other consumers of AtomicChange can use this metadata to direct how they want to consume each edit. Reviewed By: ymandel, gribozavr2 Differential Revision: https://reviews.llvm.org/D82226
Diffstat (limited to 'clang/unittests/Tooling/TransformerTest.cpp')
-rw-r--r--clang/unittests/Tooling/TransformerTest.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/clang/unittests/Tooling/TransformerTest.cpp b/clang/unittests/Tooling/TransformerTest.cpp
index d19f747..7d6b632 100644
--- a/clang/unittests/Tooling/TransformerTest.cpp
+++ b/clang/unittests/Tooling/TransformerTest.cpp
@@ -439,6 +439,29 @@ TEST_F(TransformerTest, RemoveEdit) {
Input, Expected);
}
+TEST_F(TransformerTest, WithMetadata) {
+ std::string Input = R"cc(
+ int f() {
+ int x = 5;
+ return 7;
+ }
+ )cc";
+
+ Transformer T(
+ makeRule(declStmt().bind("decl"),
+ withMetadata(remove(statement(std::string("decl"))), 17)),
+ consumer());
+ T.registerMatchers(&MatchFinder);
+ auto Factory = newFrontendActionFactory(&MatchFinder);
+ EXPECT_TRUE(runToolOnCodeWithArgs(
+ Factory->create(), Input, std::vector<std::string>(), "input.cc",
+ "clang-tool", std::make_shared<PCHContainerOperations>(), {}));
+ ASSERT_EQ(Changes.size(), 1u);
+ const llvm::Any &Metadata = Changes[0].getMetadata();
+ ASSERT_TRUE(llvm::any_isa<int>(Metadata));
+ EXPECT_THAT(llvm::any_cast<int>(Metadata), 17);
+}
+
TEST_F(TransformerTest, MultiChange) {
std::string Input = R"cc(
void foo() {