Commit 1d9d4980 authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

cmake: port foreach -> range-based for

parent 64e6ae6e
......@@ -125,8 +125,7 @@ bool followUses(KTextEditor::Document* doc, RangeInRevision r, const QString& na
doc->insertText(r.castToSimpleRange().start(), ' '+name);
ret=true;
}
else foreach(Declaration* d, decls)
{
else for (Declaration* d : qAsConst(decls)) {
r.start=d->range().end;
for(int lineNum = r.start.line; lineNum <= r.end.line; lineNum++)
......
......@@ -75,7 +75,8 @@ CMakeFilesCompilationData importCommands(const Path& commandsFile)
static const QString KEY_DIRECTORY = QStringLiteral("directory");
static const QString KEY_FILE = QStringLiteral("file");
auto rt = ICore::self()->runtimeController()->currentRuntime();
foreach(const QJsonValue& value, document.array()) {
const auto values = document.array();
for (const QJsonValue& value : values) {
if (!value.isObject()) {
qCWarning(CMAKE) << "JSON command file entry is not an object:" << value;
continue;
......
......@@ -228,8 +228,8 @@ KJob* CMakeManager::createImportJob(ProjectFolderItem* item)
QList<KDevelop::ProjectTargetItem*> CMakeManager::targets() const
{
QList<KDevelop::ProjectTargetItem*> ret;
foreach(IProject* p, m_projects.keys())
{
for (auto it = m_projects.begin(), end = m_projects.end(); it != end; ++it) {
IProject* p = it.key();
ret+=p->projectItem()->targetList();
}
return ret;
......@@ -353,7 +353,7 @@ static void populateTargets(ProjectFolderItem* folder, const QHash<KDevelop::Pat
}
}
foreach (const auto& target, dirTargets) {
for (const auto& target : qAsConst(dirTargets)) {
switch(target.type) {
case CMakeTarget::Executable:
new CMakeTargetItem(folder, target.name, target.artifacts.value(0));
......@@ -367,7 +367,8 @@ static void populateTargets(ProjectFolderItem* folder, const QHash<KDevelop::Pat
}
}
foreach (ProjectFolderItem* children, folder->folderList()) {
const auto folderItems = folder->folderList();
for (ProjectFolderItem* children : folderItems) {
populateTargets(children, targets);
}
}
......
......@@ -197,7 +197,8 @@ void CMakePreferences::configureCacheView()
if( m_currentModel ) {
m_prefsUi->cacheList->setEnabled( true );
foreach(const QModelIndex & idx, m_currentModel->persistentIndices()) {
const auto persistentIndices = m_currentModel->persistentIndices();
for (const QModelIndex& idx : persistentIndices) {
m_prefsUi->cacheList->openPersistentEditor(idx);
}
} else {
......
......@@ -70,8 +70,8 @@ void CTestFindJob::findTestCases()
return;
}
foreach (const KDevelop::Path &file, m_pendingFiles)
{
const auto currentPendingFiles = m_pendingFiles;
for (const KDevelop::Path& file : currentPendingFiles) {
KDevelop::DUChain::self()->updateContextForUrl(KDevelop::IndexedString(file.toUrl()), KDevelop::TopDUContext::AllDeclarationsAndContexts, this);
}
}
......
......@@ -62,8 +62,8 @@ static KJob* createTestJob(const QString& launchModeId, const QStringList& argum
Q_ASSERT(type && mode);
ILauncher* launcher = nullptr;
foreach (ILauncher *l, type->launchers())
{
const auto launchers = type->launchers();
for (ILauncher* l : launchers) {
//qCDebug(CMAKE) << "available launcher" << l << l->id() << l->supportedModes();
if (l->supportedModes().contains(mode->id())) {
launcher = l;
......
......@@ -47,8 +47,8 @@ Declaration* findTestClassDeclaration(const CursorInRevision& c, DUContext* ctx,
* or range.
*/
foreach(DUContext* subCtx, ctx->childContexts())
{
const auto subContexts = ctx->childContexts();
for (DUContext* subCtx : subContexts) {
//This is a little hacky, but we need it in case of foreach macros and similar stuff
if(subCtx->range().contains(c, behavior) || subCtx->range().isEmpty() || subCtx->range().start.line == c.line || subCtx->range().end.line == c.line)
{
......@@ -103,8 +103,8 @@ void CTestSuite::loadDeclarations(const IndexedString& document, const KDevelop:
Declaration* testClass = nullptr;
const auto mainId = Identifier(QStringLiteral("main"));
foreach (Declaration* declaration, topContext->findLocalDeclarations(mainId))
{
const auto mainDeclarations = topContext->findLocalDeclarations(mainId);
for (Declaration* declaration : mainDeclarations) {
if (declaration->isDefinition())
{
qCDebug(CMAKE) << "Found a definition for a function 'main()' at" << declaration->range();
......@@ -170,8 +170,8 @@ void CTestSuite::loadDeclarations(const IndexedString& document, const KDevelop:
m_suiteDeclaration = IndexedDeclaration(testClass);
}
foreach (Declaration* decl, testClass->internalContext()->localDeclarations(topContext))
{
const auto testClassDeclarations = testClass->internalContext()->localDeclarations(topContext);
for (Declaration* decl : testClassDeclarations) {
qCDebug(CMAKE) << "Found declaration" << decl->toString() << decl->identifier().identifier().byteArray();
if (auto* function = dynamic_cast<ClassFunctionDeclaration*>(decl))
{
......
......@@ -45,7 +45,8 @@ KDevProjectOpen::KDevProjectOpen(QObject* parent)
void KDevProjectOpen::cleanup()
{
foreach(IProject* p, ICore::self()->projectController()->projects()) {
const auto projects = ICore::self()->projectController()->projects();
for (IProject* p : projects) {
ICore::self()->projectController()->closeProject(p);
}
Q_ASSERT(ICore::self()->projectController()->projects().isEmpty());
......@@ -90,7 +91,8 @@ int main(int argc, char** argv)
}
KDevProjectOpen opener;
foreach(const QString& arg, parser.positionalArguments()) {
const auto args = parser.positionalArguments();
for (const QString& arg : args) {
opener.openProject(QUrl::fromUserInput(arg));
}
return app.exec();
......
......@@ -57,7 +57,8 @@ void TestCMakeManager::cleanupTestCase()
void TestCMakeManager::cleanup()
{
foreach(IProject* p, ICore::self()->projectController()->projects()) {
const auto projects = ICore::self()->projectController()->projects();
for (IProject* p : projects) {
ICore::self()->projectController()->closeProject(p);
}
QVERIFY(ICore::self()->projectController()->projects().isEmpty());
......
......@@ -68,8 +68,8 @@ void TestCTestFindSuites::initTestCase()
void TestCTestFindSuites::cleanup()
{
foreach(IProject* p, ICore::self()->projectController()->projects())
{
const auto projects = ICore::self()->projectController()->projects() ;
for (IProject* p : projects) {
if (p && p->buildSystemManager() && p->buildSystemManager()->builder())
{
p->buildSystemManager()->builder()->prune(p)->exec();
......@@ -151,8 +151,8 @@ void TestCTestFindSuites::testQtTestCases()
QCOMPARE(suite->cases(), cases);
QVERIFY(suite->declaration().isValid());
foreach (const auto& caseName, suite->cases())
{
const auto caseNames = suite->cases();
for (const auto& caseName : caseNames) {
QVERIFY(suite->caseDeclaration(caseName).isValid());
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment