forked from qt-creator/qt-creator
AutoTest: Fix reparsing of header files...
...when having split source and headers and defining test data functions inside the source file. If we just reparse a header file (e.g. when opening the respective file inside the editor) we have no explicit information where the definition of the functions is. This lead to not finding the information necessary for displaying data tags and throwing away old information as they have been marked for removal. Change-Id: Ieb8ed9f7c758fe2c793e60ca2c30b4025106363b Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
@@ -404,21 +404,23 @@ static CPlusPlus::Document::Ptr declaringDocument(CPlusPlus::Document::Ptr doc,
|
||||
return declaringDoc;
|
||||
}
|
||||
|
||||
static bool hasFunctionWithDataTagUsage(const QMap<QString, TestCodeLocationAndType> &testFunctions)
|
||||
{
|
||||
foreach (const QString &functionName, testFunctions.keys()) {
|
||||
if (functionName.endsWith(QLatin1String("_data")) &&
|
||||
testFunctions.contains(functionName.left(functionName.size() - 5))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static QMap<QString, TestCodeLocationList> checkForDataTags(const QString &fileName,
|
||||
static QSet<QString> filesWithDataFunctionDefinitions(
|
||||
const QMap<QString, TestCodeLocationAndType> &testFunctions)
|
||||
{
|
||||
if (hasFunctionWithDataTagUsage(testFunctions)) {
|
||||
QSet<QString> result;
|
||||
QMap<QString, TestCodeLocationAndType>::ConstIterator it = testFunctions.begin();
|
||||
const QMap<QString, TestCodeLocationAndType>::ConstIterator end = testFunctions.end();
|
||||
|
||||
for ( ; it != end; ++it) {
|
||||
const QString &key = it.key();
|
||||
if (key.endsWith(QLatin1String("_data")) && testFunctions.contains(key.left(key.size() - 5)))
|
||||
result.insert(it.value().m_name);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static QMap<QString, TestCodeLocationList> checkForDataTags(const QString &fileName)
|
||||
{
|
||||
const CPlusPlus::Snapshot snapshot = CPlusPlus::CppModelManagerBase::instance()->snapshot();
|
||||
const QByteArray fileContent = getFileContent(fileName);
|
||||
CPlusPlus::Document::Ptr document = snapshot.preprocessedDocument(fileContent, fileName);
|
||||
@@ -428,8 +430,6 @@ static QMap<QString, TestCodeLocationList> checkForDataTags(const QString &fileN
|
||||
visitor.accept(ast);
|
||||
return visitor.dataTags();
|
||||
}
|
||||
return QMap<QString, TestCodeLocationList>();
|
||||
}
|
||||
|
||||
/****** end of helpers ******/
|
||||
|
||||
@@ -549,12 +549,11 @@ static void checkDocumentForTestCode(QFutureInterface<TestParseResult> futureInt
|
||||
return;
|
||||
|
||||
const QMap<QString, TestCodeLocationAndType> testFunctions = visitor.privateSlots();
|
||||
const QSet<QString> &files = filesWithDataFunctionDefinitions(testFunctions);
|
||||
|
||||
QMap<QString, TestCodeLocationList> dataTags =
|
||||
checkForDataTags(declaringDoc->fileName(), testFunctions);
|
||||
|
||||
if (declaringDoc->fileName() != document->fileName())
|
||||
dataTags.unite(checkForDataTags(document->fileName(), testFunctions));
|
||||
QMap<QString, TestCodeLocationList> dataTags;
|
||||
foreach (const QString &file, files)
|
||||
dataTags.unite(checkForDataTags(file));
|
||||
|
||||
TestParseResult parseResult(TestTreeModel::AutoTest);
|
||||
parseResult.fileName = declaringDoc->fileName();
|
||||
|
Reference in New Issue
Block a user