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

Use only const containers in range-loops

Powered by (kdev)clazy
parent 5a96f159
......@@ -64,6 +64,7 @@
#include <interfaces/launchconfigurationtype.h>
#include <util/path.h>
#include <debug.h>
#include <qtcompat_p.h>
#include "kdevideextension.h"
#if KDEVELOP_SINGLE_APP
......@@ -805,7 +806,7 @@ int main( int argc, char *argv[] )
} else {
openFiles(initialFiles);
for(const auto &urlinfo: initialDirectories)
for(const auto& urlinfo: qAsConst(initialDirectories))
core->projectController()->openProjectForUrl(urlinfo.url);
}
......
......@@ -123,7 +123,7 @@ void populateMenuWithGroup(
}
}
for (QAction* action : groupActions) {
for (QAction* action : qAsConst(groupActions)) {
groupMenu->addAction(action);
}
......
......@@ -29,6 +29,8 @@ Boston, MA 02110-1301, USA.
#include <editor/documentrange.h>
#include <interfaces/iassistant.h>
#include <qtcompat_p.h>
#include <KLocalizedString>
namespace KDevelop {
......@@ -122,7 +124,7 @@ QVector<IProblem::Ptr> Problem::diagnostics() const
{
QVector<IProblem::Ptr> vector;
for (ProblemPointer ptr : m_diagnostics) {
for (const auto& ptr : qAsConst(m_diagnostics)) {
vector.push_back(ptr);
}
......
......@@ -32,6 +32,7 @@
#include <tests/testplugincontroller.h>
#include <util/path.h>
#include <qtcompat_p.h>
#include <KJob>
#include <KDirWatch>
......@@ -174,7 +175,7 @@ int main(int argc, char** argv)
}
runTimer.start();
for (auto benchmark : benchmarks) {
for (auto benchmark : qAsConst(benchmarks)) {
benchmark->start();
}
......
......@@ -194,8 +194,8 @@ QList<KTextEditor::MainWindow *> Application::mainWindows() const
bool Application::closeDocument(KTextEditor::Document *document) const
{
auto documentController = Core::self()->documentControllerInternal();
for (auto doc : documentController->openDocuments()) {
const auto& openDocuments = Core::self()->documentControllerInternal()->openDocuments();
for (auto doc : openDocuments) {
if (doc->textDocument() == document) {
return doc->close();
}
......
......@@ -24,6 +24,7 @@
#include <QMutexLocker>
#include <QThread>
#include <qtcompat_p.h>
#include <interfaces/idocument.h>
#include <interfaces/idocumentcontroller.h>
#include <interfaces/iplugin.h>
......@@ -223,7 +224,7 @@ ILanguageSupport* LanguageController::language(const QString &name) const
constraints.insert(key, name);
supports = Core::self()->pluginController()->allPluginsForExtension(KEY_ILanguageSupport(), constraints);
if (key == keys[1]) {
for (auto support : supports) {
for (auto support : qAsConst(supports)) {
qCWarning(SHELL) << "Plugin" << Core::self()->pluginController()->pluginInfo(support).name() << " has deprecated (since 5.1) metadata key \"X-KDevelop-Language\", needs porting to: \"X-KDevelop-Languages\": ["<<name<<"]'";
}
}
......
......@@ -78,7 +78,8 @@ void TemplatePage::loadFromFile()
return;
}
for (const auto& file : fileDialog->selectedFiles()) {
const auto& selectedFiles = fileDialog->selectedFiles();
for (const auto& file : selectedFiles) {
m_provider->loadTemplate(file);
}
......
......@@ -31,6 +31,7 @@
#include <util/scopeddialog.h>
#include <language/interfaces/ilanguagesupport.h>
#include <interfaces/ilanguagecontroller.h>// TODO: remove later
#include <qtcompat_p.h>
#include <KMessageBox>
#include <KTextEditor/Editor>
......@@ -118,7 +119,8 @@ SourceFormatterSelectionEdit::SourceFormatterSelectionEdit(QWidget* parent)
this, &SourceFormatterSelectionEdit::addSourceFormatter);
connect(controller, &SourceFormatterController::formatterUnloading,
this, &SourceFormatterSelectionEdit::removeSourceFormatter);
for (auto* formatter : controller->formatters()) {
const auto& formatters = controller->formatters();
for (auto* formatter : formatters) {
addSourceFormatter(formatter);
}
}
......@@ -318,7 +320,7 @@ void SourceFormatterSelectionEdit::saveSettings(KConfigGroup& config)
globalConfig.sync();
// store selected formatters in given language
for (const auto& setting : d->languages) {
for (const auto& setting : qAsConst(d->languages)) {
for(const auto& mime : setting.mimetypes) {
const QString formatterId = setting.selectedFormatter->formatter->name() + QLatin1String("||") + setting.selectedStyle->name();
config.writeEntry(mime.name(), formatterId);
......
......@@ -286,7 +286,8 @@ QString AppWizardPlugin::createProject(const ApplicationInfo& info)
// but could be different name, if e.g. downloaded, so make a guess
if (!templateEntry || !templateEntry->isFile()) {
for (const auto& entryName : arch->directory()->entries()) {
const auto& entries = arch->directory()->entries();
for (const auto& entryName : entries) {
if (entryName.endsWith(QLatin1String(".kdevtemplate"))) {
templateEntry = arch->directory()->entry(entryName);
break;
......
......@@ -310,7 +310,8 @@ void ProjectSelectionPage::loadFileClicked()
return;
}
for (const auto& fileName : fileDialog->selectedFiles()) {
const auto& fileNames = fileDialog->selectedFiles();
for (const auto& fileName : fileNames) {
QString destination = m_templatesModel->loadTemplateFile(fileName);
QModelIndexList indexes = m_templatesModel->templateIndexes(destination);
if (indexes.size() > 2)
......
......@@ -121,7 +121,8 @@ ProjectFileItem* findProjectFileItem(const IndexedString& url, bool* hasBuildSys
ProjectFileItem* file = nullptr;
*hasBuildSystemInfo = false;
for (auto project: ICore::self()->projectController()->projects()) {
const auto& projects = ICore::self()->projectController()->projects();
for (auto project : projects) {
auto files = project->filesForPath(url);
if (files.isEmpty()) {
continue;
......
......@@ -201,7 +201,8 @@ ClangSupport::ClangSupport(QObject* parent, const QVariantList& )
this, &ClangSupport::disableKeywordCompletion);
connect(model, &CodeCompletion::unregisteredFromView,
this, &ClangSupport::enableKeywordCompletion);
for(const auto& type : DocumentFinderHelpers::mimeTypesList()){
const auto& mimeTypes = DocumentFinderHelpers::mimeTypesList();
for (const auto& type : mimeTypes) {
KDevelop::IBuddyDocumentFinder::addFinder(type, this);
}
......@@ -219,7 +220,8 @@ ClangSupport::~ClangSupport()
// By locking the parse-mutexes, we make sure that parse jobs get a chance to finish in a good state
parseLock()->unlock();
for(const auto& type : DocumentFinderHelpers::mimeTypesList()) {
const auto& mimeTypes = DocumentFinderHelpers::mimeTypesList();
for (const auto& type : mimeTypes) {
KDevelop::IBuddyDocumentFinder::removeFinder(type);
}
......
......@@ -44,6 +44,7 @@
#include <language/codecompletion/codecompletionmodel.h>
#include <language/codecompletion/normaldeclarationcompletionitem.h>
#include <util/foregroundlock.h>
#include <qtcompat_p.h>
#include "../util/clangdebug.h"
#include "../util/clangtypes.h"
......@@ -670,7 +671,7 @@ public:
QList<CompletionTreeItemPointer> matchedItems()
{
QList<CompletionTreeItemPointer> lookAheadItems;
for (const auto& pair: possibleLookAheadDeclarations) {
for (const auto& pair: qAsConst(possibleLookAheadDeclarations)) {
auto decl = pair.first;
if (matchedTypes.contains(decl->indexedType())) {
auto parent = pair.second;
......@@ -700,7 +701,8 @@ private:
return;
}
for (auto localDecl : typeDecl->internalContext()->localDeclarations()) {
const auto& localDeclarations = typeDecl->internalContext()->localDeclarations();
for (auto localDecl : localDeclarations) {
if(localDecl->identifier().isEmpty()){
continue;
}
......@@ -831,7 +833,7 @@ ClangCodeCompletionContext::ClangCodeCompletionContext(const DUContextPointer& c
unsaved.Length = content.size();
allUnsaved.reserve(otherUnsavedFiles.size() + 1);
for ( const auto& f : otherUnsavedFiles ) {
for (const auto& f : qAsConst(otherUnsavedFiles)) {
allUnsaved.append(f.toClangApi());
}
allUnsaved.append(unsaved);
......
......@@ -26,6 +26,7 @@
#include "duchain/clanghelpers.h"
#include <language/codecompletion/abstractincludefilecompletionitem.h>
#include <qtcompat_p.h>
#include <QDirIterator>
......@@ -163,7 +164,7 @@ QVector<KDevelop::IncludeItem> includeItemsForUrl(const QUrl& url, const Include
QSet<QString> foundIncludePaths; // found items
int pathNumber = 0;
for (auto searchPath : paths) {
for (auto searchPath : qAsConst(paths)) {
if (handledPaths.contains(searchPath)) {
continue;
}
......@@ -283,7 +284,7 @@ QList< CompletionTreeItemPointer > IncludePathCompletionContext::completionItems
{
QList<CompletionTreeItemPointer> items;
for (const auto& includeItem: m_includeItems) {
for (const auto& includeItem: qAsConst(m_includeItems)) {
if (abort) {
return items;
}
......
......@@ -283,7 +283,8 @@ QVariantHash ClangTemplateNewClass::extraVariables() const
}
const Path sourcePath(sourceUrl);
for (const auto& baseClass : directBaseClasses()) {
const auto& directBaseClasses = this->directBaseClasses();
for (const auto& baseClass : directBaseClasses) {
if (!baseClass) {
continue;
}
......
......@@ -28,6 +28,7 @@
#include <language/duchain/duchainlock.h>
#include <language/codegen/documentchangeset.h>
#include <qtcompat_p.h>
#include <KLocalizedString>
......@@ -185,7 +186,8 @@ ClangFixits ClangProblem::allFixits() const
ClangFixits result;
result << m_fixits;
for (const IProblem::Ptr& diagnostic : diagnostics()) {
const auto& diagnostics = this->diagnostics();
for (const IProblem::Ptr& diagnostic : diagnostics) {
const Ptr problem(dynamic_cast<ClangProblem*>(diagnostic.data()));
Q_ASSERT(problem);
result << problem->allFixits();
......@@ -214,7 +216,7 @@ void ClangFixitAssistant::createActions()
{
KDevelop::IAssistant::createActions();
for (const ClangFixit& fixit : m_fixits) {
for (const ClangFixit& fixit : qAsConst(m_fixits)) {
addAction(IAssistantAction::Ptr(new ClangFixitAction(fixit)));
}
}
......
......@@ -44,7 +44,8 @@ public:
modifyHtml() += QStringLiteral("< ").toHtmlEscaped();
bool first = true;
for (const auto& type : cst->templateParameters()) {
const auto& templateParameters = cst->templateParameters();
for (const auto& type : templateParameters) {
if (first) {
first = false;
} else {
......
......@@ -107,7 +107,8 @@ QString ClassSpecializationType::toString() const
if (!id.isEmpty()) {
QString result = AbstractType::toString() + strippedQid(id) + QLatin1String("< ");
bool first = true;
for (const auto& param : templateParameters()) {
const auto& templateParameters = this->templateParameters();
for (const auto& param : templateParameters) {
if (first) {
first = false;
} else {
......
......@@ -95,7 +95,8 @@ QStringList scanIncludePaths( const QString& identifier, const QDir& dir, int ma
}
const QStringList nameFilters = {identifier, identifier + QLatin1String(".*")};
for (const auto& file : dir.entryList(nameFilters, QDir::Files)) {
const auto& files = dir.entryList(nameFilters, QDir::Files);
for (const auto& file : files) {
if (identifier.compare(file, Qt::CaseInsensitive) == 0 || ClangHelpers::isHeader(file)) {
const QString filePath = path + QLatin1Char('/') + file;
clangDebug() << "Found candidate file" << filePath;
......@@ -104,8 +105,10 @@ QStringList scanIncludePaths( const QString& identifier, const QDir& dir, int ma
}
maxDepth--;
for( const auto& subdir : dir.entryList( QDir::Dirs | QDir::NoDotAndDotDot ) )
const auto& subdirs = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
for (const auto& subdir : subdirs) {
candidates += scanIncludePaths( identifier, QDir{ path + QLatin1Char('/') + subdir }, maxDepth );
}
return candidates;
}
......@@ -170,7 +173,8 @@ KDevelop::DocumentRange includeDirectivePosition(const KDevelop::Path& source, c
// look at existing #include statements and re-use them
int currentMatchQuality = -1;
for( const auto& import : top->importedParentContexts() ) {
const auto& importedParentContexts = top->importedParentContexts();
for (const auto& import : importedParentContexts) {
const auto importFilename = import.context(top)->url().str();
const int matchQuality = sharedPathLevel( importFilename , includeFile );
......@@ -211,7 +215,8 @@ KDevelop::DocumentRange forwardDeclarationPosition(const QualifiedIdentifier& id
}
int line = std::numeric_limits< int >::max();
for( const auto decl : top->localDeclarations() ) {
const auto& localDeclarations = top->localDeclarations();
for (const auto decl : localDeclarations) {
line = std::min( line, decl->range().start.line );
}
......@@ -302,7 +307,8 @@ QStringList UnknownDeclarationProblem::findMatchingIncludeFiles(const QVector<De
clangDebug() << "Adding" << filepath << "determined from candidate" << decl->toString();
}
for( const auto importer : file->importers() ) {
const auto& importers = file->importers();
for (const auto& importer : importers) {
if( importer->imports().count() != 1 && !isBlacklisted( filepath ) ) {
continue;
}
......@@ -491,7 +497,8 @@ ClangFixits fixUnknownDeclaration( const QualifiedIdentifier& identifier, const
const auto matchingDeclarations = findMatchingDeclarations(possibleIdentifiers);
if (ClangSettingsManager::self()->assistantsSettings().forwardDeclare) {
for (const auto& fixit : forwardDeclarations(matchingDeclarations, file)) {
const auto& forwardDeclareFixits = forwardDeclarations(matchingDeclarations, file);
for (const auto& fixit : forwardDeclareFixits) {
fixits << fixit;
if (fixits.size() == maxSuggestions) {
return fixits;
......
......@@ -2079,7 +2079,8 @@ void TestDUChain::testHasInclude()
QVERIFY(headerCtx);
dumper.dump(headerCtx);
QVERIFY(headerCtx->problems().count() <= 1);
for (const auto& problem : headerCtx->problems()) {
const auto& headerProblems = headerCtx->problems();
for (const auto& problem : headerProblems) {
// ignore the following error: "#include_next with absolute path [-Winclude-next-absolute-path]" "" [ (2, 12) -> (2, 30) ]
QVERIFY(problem->description().contains(QLatin1String("-Winclude-next-absolute-path")));
}
......
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