Clang: Add refactoring support for unsaved content

We need the generated UI header but we don't have a build directory. So we
provide clang with in memory represations of the file.

Change-Id: Ie9db97bbea2222b0203a0457baa1f1fc7ad97213
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2016-11-30 15:29:36 +01:00
parent 636eea99f4
commit 15de02ea0c
13 changed files with 227 additions and 56 deletions

View File

@@ -74,6 +74,20 @@ TEST_F(ClangQuery, RootSourceRangeForSimpleFunctionDeclarationRange)
IsSourceRangeWithText(1, 1, 8, 2, "int function(int* pointer, int value)\n{\n if (pointer == nullptr) {\n return value + 1;\n } else {\n return value - 1;\n }\n}"));
}
TEST_F(ClangQuery, SourceRangeInUnsavedFileDeclarationRange)
{
::ClangQuery query;
query.addFile(TESTDATA_DIR, "query_simplefunction.cpp", "#include \"unsaved.h\"", {"cc", "query_simplefunction.cpp", "-std=c++14"});
query.setQuery("functionDecl()");
ClangBackEnd::V2::FileContainer unsavedFile{{TESTDATA_DIR, "unsaved.h"}, "void unsaved();", {}};
query.addUnsavedFiles({unsavedFile});
query.findLocations();
ASSERT_THAT(query.takeSourceRanges().sourceRangeWithTextContainers().at(0),
IsSourceRangeWithText(1, 1, 1, 15, "void unsaved();"));
}
TEST_F(ClangQuery, RootSourceRangeForSimpleFieldDeclarationRange)
{
simpleClassQuery.setQuery("fieldDecl(hasType(isInteger()))");