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

kdevplastform/language/codegen: port foreach -> range-based for

parent 3ff40c0e
......@@ -56,18 +56,14 @@ void ArchiveTemplateLoader::removeLocation(ArchiveTemplateLocation* location)
bool ArchiveTemplateLoader::canLoadTemplate(const QString& name) const
{
foreach (ArchiveTemplateLocation* location, d->locations) {
if (location->hasTemplate(name)) {
return true;
}
}
return false;
return std::any_of(d->locations.constBegin(), d->locations.constEnd(), [&](ArchiveTemplateLocation* location) {
return (location->hasTemplate(name));
});
}
Grantlee::Template ArchiveTemplateLoader::loadByName(const QString& name, const Grantlee::Engine* engine) const
{
foreach (ArchiveTemplateLocation* location, d->locations) {
for (ArchiveTemplateLocation* location : qAsConst(d->locations)) {
if (location->hasTemplate(name)) {
return engine->newTemplate(location->templateContents(name), name);
}
......
......@@ -177,7 +177,8 @@ DocumentChangeSet::ChangeResult BasicRefactoring::applyChanges(const QString& ol
return result;
}
foreach (DUContext* child, context->childContexts()) {
const auto childContexts = context->childContexts();
for (DUContext* child : childContexts) {
DocumentChangeSet::ChangeResult result = applyChanges(oldName, newName, changes, child, usedDeclarationIndex);
if (!result)
return result;
......@@ -332,9 +333,11 @@ DocumentChangeSet BasicRefactoring::renameCollectedDeclarations(KDevelop::BasicR
DocumentChangeSet changes;
DUChainReadLocker lock;
foreach (const KDevelop::IndexedTopDUContext collected, collector->allUsingContexts()) {
const auto allUsingContexts = collector->allUsingContexts();
for (const KDevelop::IndexedTopDUContext collected : allUsingContexts) {
QSet<int> hadIndices;
foreach (const IndexedDeclaration decl, collector->declarations()) {
const auto declarations = collector->declarations();
for (const IndexedDeclaration decl : declarations) {
uint usedDeclarationIndex = collected.data()->indexForUsedDeclaration(decl.data(), false);
if (hadIndices.contains(usedDeclarationIndex))
continue;
......
......@@ -108,8 +108,7 @@ void CodeGeneratorBase::setErrorText(const QString& errorText)
void CodeGeneratorBase::clearChangeSets()
{
qCDebug(LANGUAGE) << "Cleaning up all the changesets registered by the generator";
foreach (DUChainChangeSet* changeSet, d->duchainChanges)
delete changeSet;
qDeleteAll(d->duchainChanges);
d->duchainChanges.clear();
......
......@@ -296,8 +296,10 @@ DocumentChangeSet::ChangeResult DocumentChangeSet::applyAllChanges()
result = d->replaceOldText(codeRepresentations[file].data(), newTexts[file], filteredSortedChanges[file]);
if (!result && d->replacePolicy == StopOnFailedChange) {
//Revert all files
foreach (const IndexedString& revertFile, oldTexts.keys()) {
codeRepresentations[revertFile]->setText(oldTexts[revertFile]);
for (auto it = oldTexts.constBegin(), end = oldTexts.constEnd(); it != end; ++it) {
const IndexedString& revertFile = it.key();
const QString& oldText = it.value();
codeRepresentations[revertFile]->setText(oldText);
}
return result;
......@@ -484,7 +486,7 @@ DocumentChangeSet::ChangeResult DocumentChangeSetPrivate::generateNewText(const
if (!removedLines.isEmpty()) {
int offset = 0;
std::sort(removedLines.begin(), removedLines.end());
foreach (int l, removedLines) {
for (int l : qAsConst(removedLines)) {
textLines.removeAt(l - offset);
++offset;
}
......@@ -500,7 +502,7 @@ DocumentChangeSet::ChangeResult DocumentChangeSetPrivate::removeDuplicates(const
using ChangesMap = QMultiMap<KTextEditor::Cursor, DocumentChangePointer>;
ChangesMap sortedChanges;
foreach (const DocumentChangePointer& change, changes[file]) {
for (const DocumentChangePointer& change : qAsConst(changes[file])) {
sortedChanges.insert(change->m_range.end(), change);
}
......@@ -558,7 +560,8 @@ DocumentChangeSet::ChangeResult DocumentChangeSetPrivate::removeDuplicates(const
void DocumentChangeSetPrivate::updateFiles()
{
ModificationRevisionSet::clearCache();
foreach (const IndexedString& file, changes.keys()) {
const auto files = changes.keys();
for (const IndexedString& file : files) {
ModificationRevision::clearModificationCache(file);
}
......@@ -569,8 +572,8 @@ void DocumentChangeSetPrivate::updateFiles()
}
// If there are currently open documents that now need an update, update them too
foreach (const IndexedString& doc,
ICore::self()->languageController()->backgroundParser()->managedDocuments()) {
const auto documents = ICore::self()->languageController()->backgroundParser()->managedDocuments();
for (const IndexedString& doc : documents) {
DUChainReadLocker lock(DUChain::lock());
TopDUContext* top = DUChainUtils::standardContextForUrl(doc.toUrl(), true);
if ((top && top->parsingEnvironmentFile() && top->parsingEnvironmentFile()->needsUpdate()) || !top) {
......@@ -580,7 +583,8 @@ void DocumentChangeSetPrivate::updateFiles()
}
// Eventually update _all_ affected files
foreach (const IndexedString& file, changes.keys()) {
const auto files = changes.keys();
for (const IndexedString& file : files) {
if (!file.toUrl().isValid()) {
qCWarning(LANGUAGE) << "Trying to apply changes to an invalid document";
continue;
......
......@@ -33,8 +33,7 @@ DUChainChangeSet::DUChainChangeSet(const ReferencedTopDUContext& topContext) :
DUChainChangeSet::~DUChainChangeSet()
{
foreach (DUChainRef* reference, m_objectRefs)
delete reference;
qDeleteAll(m_objectRefs);
}
DUChainChangeSet& DUChainChangeSet::operator<<(DUChainChangeSet& rhs)
......
......@@ -167,8 +167,9 @@ void SourceFileTemplate::setTemplateDescription(const QString& templateDescripti
QStringLiteral("/kdevfiletemplates/templates/"),
QStandardPaths::LocateDirectory));
foreach (const QString& dir, d->searchLocations) {
foreach (const auto& entry, QDir(dir).entryInfoList(QDir::Files)) {
for (const QString& dir : qAsConst(d->searchLocations)) {
const auto fileEntries = QDir(dir).entryInfoList(QDir::Files);
for (const auto& entry : fileEntries) {
if (entry.baseName() == templateBaseName) {
archiveFileName = entry.absoluteFilePath();
qCDebug(LANGUAGE) << "Found template archive" << archiveFileName;
......
......@@ -84,7 +84,8 @@ void TemplateClassGeneratorPrivate::fetchSuperClasses(const DeclarationPointer&
DUContext* context = declaration->internalContext();
if (context) {
foreach (const DUContext::Import& import, context->importedParentContexts()) {
const auto importedParentContexts = context->importedParentContexts();
for (const DUContext::Import& import : importedParentContexts) {
if (DUContext* parentContext = import.context(context->topContext())) {
if (parentContext->type() == DUContext::Class) {
fetchSuperClasses(DeclarationPointer(parentContext->owner()));
......@@ -121,7 +122,9 @@ QHash<QString, QString> TemplateClassGenerator::fileLabels() const
Q_ASSERT(d->fileTemplate.isValid());
QHash<QString, QString> labels;
foreach (const SourceFileTemplate::OutputFile& outputFile, d->fileTemplate.outputFiles()) {
const auto outputFiles = d->fileTemplate.outputFiles();
labels.reserve(outputFiles.size());
for (const SourceFileTemplate::OutputFile& outputFile : outputFiles) {
labels.insert(outputFile.identifier, outputFile.label);
}
......@@ -131,7 +134,8 @@ QHash<QString, QString> TemplateClassGenerator::fileLabels() const
TemplateClassGenerator::UrlHash TemplateClassGenerator::fileUrls() const
{
if (d->fileUrls.isEmpty()) {
foreach (const SourceFileTemplate::OutputFile& outputFile, d->fileTemplate.outputFiles()) {
const auto outputFiles = d->fileTemplate.outputFiles();
for (const SourceFileTemplate::OutputFile& outputFile : outputFiles) {
QString outputName = d->renderer.render(outputFile.outputName, outputFile.identifier);
QUrl url = d->baseUrl.resolved(QUrl(outputName));
d->fileUrls.insert(outputFile.identifier, url);
......
......@@ -250,7 +250,8 @@ DocumentChangeSet TemplateRenderer::renderFileTemplate(const SourceFileTemplate&
const KArchiveDirectory* directory = fileTemplate.directory();
ArchiveTemplateLocation location(directory);
foreach (const SourceFileTemplate::OutputFile& outputFile, fileTemplate.outputFiles()) {
const auto outputFiles = fileTemplate.outputFiles();
for (const SourceFileTemplate::OutputFile& outputFile : outputFiles) {
const KArchiveEntry* entry = directory->entry(outputFile.fileName);
if (!entry) {
qCWarning(LANGUAGE) << "Entry" << outputFile.fileName << "is mentioned in group" << outputFile.identifier <<
......
......@@ -114,7 +114,7 @@ void TemplatesModel::refresh()
d->extractTemplateDescriptions();
QStringList templateArchives;
foreach (const QString& archivePath, d->searchPaths) {
for (const QString& archivePath : qAsConst(d->searchPaths)) {
const QStringList files = QDir(archivePath).entryList(QDir::Files);
for (const QString& file : files) {
templateArchives.append(archivePath + file);
......@@ -132,10 +132,10 @@ void TemplatesModel::refresh()
}
}
foreach (const QString& templateDescription, templateDescriptions) {
for (const QString& templateDescription : qAsConst(templateDescriptions)) {
QFileInfo fi(templateDescription);
bool archiveFound = false;
foreach (const QString& templateArchive, templateArchives) {
for (const QString& templateArchive : qAsConst(templateArchives)) {
if (QFileInfo(templateArchive).baseName() == fi.baseName()) {
archiveFound = true;
......@@ -194,7 +194,7 @@ void TemplatesModelPrivate::extractTemplateDescriptions()
searchPaths << QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, resourceFilter(
Template), QStandardPaths::LocateDirectory);
searchPaths.removeDuplicates();
foreach (const QString& archivePath, searchPaths) {
for (const QString& archivePath : qAsConst(searchPaths)) {
const QStringList files = QDir(archivePath).entryList(QDir::Files);
for (const QString& file : files) {
if (file.endsWith(QLatin1String(".zip")) || file.endsWith(QLatin1String(".tar.bz2"))) {
......@@ -211,7 +211,7 @@ void TemplatesModelPrivate::extractTemplateDescriptions()
if (!dir.exists())
dir.mkpath(QStringLiteral("."));
foreach (const QString& archName, templateArchives) {
for (const QString& archName : qAsConst(templateArchives)) {
qCDebug(LANGUAGE) << "processing template" << archName;
QScopedPointer<KArchive> templateArchive;
......
......@@ -290,8 +290,8 @@ void TestTemplateClassGenerator::yamlOutput()
TemplateClassGenerator* TestTemplateClassGenerator::loadTemplate (const QString& name)
{
QDir dir(baseUrl.toLocalFile());
foreach (const QString& fileName, dir.entryList(QDir::Files | QDir::NoDotAndDotDot))
{
const auto files = dir.entryList(QDir::Files | QDir::NoDotAndDotDot);
for (const QString& fileName : files) {
dir.remove(fileName);
}
......
......@@ -86,9 +86,11 @@ IndexedString fetchImplementationFileForClass(const Declaration& targetClass)
}
QMultiMap<unsigned int, IndexedString> sorter;
foreach (const IndexedString& file, implementationsInFile.keys())
sorter.insert(implementationsInFile[file], file);
for (auto it = implementationsInFile.constBegin(), end = implementationsInFile.constEnd(); it != end; ++it) {
const IndexedString& file = it.key();
unsigned int count = it.value();
sorter.insert(count, file);
}
QList<IndexedString> sortedFiles = sorter.values();
//If there are no methods, then just return the file the declaration is in
......
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