From 9067399e379d50176a373ff07386c10451267723 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 28 Jun 2012 14:59:36 +0200 Subject: [PATCH] refactor relation between parsedProBlock() & parsedProFile() this is clearer and not necessarily more code. Change-Id: Ic698a8076658ae986d0dbdeebb1f4760dd806e35 Reviewed-by: Daniel Teske Reviewed-by: Oswald Buddenhagen --- src/shared/proparser/qmakeparser.cpp | 16 +++++++++++++--- src/shared/proparser/qmakeparser.h | 7 ++----- tests/auto/profilewriter/tst_profilewriter.cpp | 10 +++++----- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/shared/proparser/qmakeparser.cpp b/src/shared/proparser/qmakeparser.cpp index 4e4b0388449..3cb30b2bc9a 100644 --- a/src/shared/proparser/qmakeparser.cpp +++ b/src/shared/proparser/qmakeparser.cpp @@ -131,7 +131,7 @@ QMakeParser::QMakeParser(ProFileCache *cache, QMakeParserHandler *handler) initialize(); } -ProFile *QMakeParser::parsedProFile(const QString &fileName, bool cache, const QString *contents) +ProFile *QMakeParser::parsedProFile(const QString &fileName, bool cache) { ProFile *pro; if (cache && m_cache) { @@ -163,7 +163,7 @@ ProFile *QMakeParser::parsedProFile(const QString &fileName, bool cache, const Q locker.unlock(); #endif pro = new ProFile(fileName); - if (!(!contents ? read(pro) : read(pro, *contents))) { + if (!read(pro)) { delete pro; pro = 0; } else { @@ -183,7 +183,7 @@ ProFile *QMakeParser::parsedProFile(const QString &fileName, bool cache, const Q } } else { pro = new ProFile(fileName); - if (!(!contents ? read(pro) : read(pro, *contents))) { + if (!read(pro)) { delete pro; pro = 0; } @@ -191,6 +191,16 @@ ProFile *QMakeParser::parsedProFile(const QString &fileName, bool cache, const Q return pro; } +ProFile *QMakeParser::parsedProBlock(const QString &name, const QString &contents) +{ + ProFile *pro = new ProFile(name); + if (!read(pro, contents)) { + delete pro; + pro = 0; + } + return pro; +} + bool QMakeParser::read(ProFile *pro) { QFile file(pro->fileName()); diff --git a/src/shared/proparser/qmakeparser.h b/src/shared/proparser/qmakeparser.h index b5d36d1da40..b369ac48841 100644 --- a/src/shared/proparser/qmakeparser.h +++ b/src/shared/proparser/qmakeparser.h @@ -61,11 +61,8 @@ public: QMakeParser(ProFileCache *cache, QMakeParserHandler *handler); // fileName is expected to be absolute and cleanPath()ed. - // If contents is non-null, it will be used instead of the file's actual content - ProFile *parsedProFile(const QString &fileName, bool cache = false, - const QString *contents = 0); - ProFile *parsedProBlock(const QString &name, const QString &contents) - { return parsedProFile(name, false, &contents); } + ProFile *parsedProFile(const QString &fileName, bool cache = false); + ProFile *parsedProBlock(const QString &name, const QString &contents); private: struct BlockScope { diff --git a/tests/auto/profilewriter/tst_profilewriter.cpp b/tests/auto/profilewriter/tst_profilewriter.cpp index 0f422581087..61b02a0bf4a 100644 --- a/tests/auto/profilewriter/tst_profilewriter.cpp +++ b/tests/auto/profilewriter/tst_profilewriter.cpp @@ -451,7 +451,7 @@ void tst_ProFileWriter::adds() QString var = QLatin1String("SOURCES"); QMakeParser parser(0, &parseHandler); - ProFile *proFile = parser.parsedProFile(QLatin1String(BASE_DIR "/test.pro"), false, &input); + ProFile *proFile = parser.parsedProBlock(QLatin1String(BASE_DIR "/test.pro"), input); QVERIFY(proFile); PW::putVarValues(proFile, &lines, values, var, PW::PutFlags(flags), scope); proFile->deref(); @@ -621,7 +621,7 @@ void tst_ProFileWriter::removes() QStringList vars; vars << QLatin1String("SOURCES"); QMakeParser parser(0, &parseHandler); - ProFile *proFile = parser.parsedProFile(QLatin1String(BASE_DIR "/test.pro"), false, &input); + ProFile *proFile = parser.parsedProBlock(QLatin1String(BASE_DIR "/test.pro"), input); QVERIFY(proFile); Qt4ProjectManager::Internal::ProWriter::removeVarValues(proFile, &lines, values, vars); proFile->deref(); @@ -649,7 +649,7 @@ void tst_ProFileWriter::multiVar() QStringList vars; vars << QLatin1String("SOURCES") << QLatin1String("HEADERS"); QMakeParser parser(0, &parseHandler); - ProFile *proFile = parser.parsedProFile(QLatin1String(BASE_DIR "/test.pro"), false, &input); + ProFile *proFile = parser.parsedProBlock(QLatin1String(BASE_DIR "/test.pro"), input); QVERIFY(proFile); Qt4ProjectManager::Internal::ProWriter::removeFiles(proFile, &lines, baseDir, files, vars); proFile->deref(); @@ -669,7 +669,7 @@ void tst_ProFileWriter::addFiles() ); QMakeParser parser(0, &parseHandler); - ProFile *proFile = parser.parsedProFile(QLatin1String(BASE_DIR "/test.pro"), false, &input); + ProFile *proFile = parser.parsedProBlock(QLatin1String(BASE_DIR "/test.pro"), input); QVERIFY(proFile); Qt4ProjectManager::Internal::ProWriter::addFiles(proFile, &lines, QDir(BASE_DIR), QStringList() << QString::fromLatin1(BASE_DIR "/sub/bar.cpp"), @@ -690,7 +690,7 @@ void tst_ProFileWriter::removeFiles() ); QMakeParser parser(0, &parseHandler); - ProFile *proFile = parser.parsedProFile(QLatin1String(BASE_DIR "/test.pro"), false, &input); + ProFile *proFile = parser.parsedProBlock(QLatin1String(BASE_DIR "/test.pro"), input); QVERIFY(proFile); Qt4ProjectManager::Internal::ProWriter::removeFiles(proFile, &lines, QDir(BASE_DIR), QStringList() << QString::fromLatin1(BASE_DIR "/sub/bar.cpp"),