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

kdevplastform/language/duchain/navigation: port foreach -> range-based for

parent d3b95366
......@@ -408,7 +408,8 @@ void AbstractDeclarationNavigationContext::htmlFunction()
if (DUContext* argumentContext = DUChainUtils::argumentContext(d->m_declaration.data())) {
decls = argumentContext->localDeclarations(topContext().data());
}
foreach (const AbstractType::Ptr& argType, type->arguments()) {
const auto argTypes = type->arguments();
for (const AbstractType::Ptr& argType : argTypes) {
if (!first)
modifyHtml() += QStringLiteral(", ");
first = false;
......@@ -487,7 +488,8 @@ void AbstractDeclarationNavigationContext::htmlAdditionalNavigation()
} else {
//Check if this declarations hides other declarations
QList<Declaration*> decls;
foreach (const DUContext::Import& import, d->m_declaration->context()->importedParentContexts())
const auto importedParentContexts = d->m_declaration->context()->importedParentContexts();
for (const DUContext::Import& import : importedParentContexts) {
if (import.context(topContext().data()))
decls +=
import.context(topContext().data())->findDeclarations(QualifiedIdentifier(d->m_declaration->
......@@ -496,9 +498,10 @@ void AbstractDeclarationNavigationContext::htmlAdditionalNavigation()
AbstractType::Ptr(),
topContext().data(),
DUContext::DontSearchInParent);
}
uint num = 0;
foreach (Declaration* decl, decls) {
for (Declaration* decl : qAsConst(decls)) {
modifyHtml() += i18n("Hides a ");
makeLink(i18n("function"), QStringLiteral("jump_to_hide_%1").arg(num),
NavigationAction(DeclarationPointer(decl),
......
......@@ -58,9 +58,11 @@ TopDUContext* pickContextWithData(const QList<TopDUContext*>& duchains, uint max
if (maxDepth != 0) {
for (TopDUContext* ctx : duchains) {
QList<TopDUContext*> children;
foreach (const DUContext::Import& import, ctx->importedParentContexts())
const auto importedParentContexts = ctx->importedParentContexts();
for (const DUContext::Import& import : importedParentContexts) {
if (import.context(nullptr))
children << import.context(nullptr)->topContext();
}
duchain = pickContextWithData(children, maxDepth - 1, type, false);
if (duchain)
......
......@@ -525,7 +525,8 @@ static QStringList splitAndKeep(QString str, const QRegExp& regExp)
void AbstractNavigationContext::addHtml(const QString& html)
{
QRegExp newLineRegExp(QStringLiteral("<br>|<br */>|</p>"));
foreach (const QString& line, splitAndKeep(html, newLineRegExp)) {
const auto lines = splitAndKeep(html, newLineRegExp);
for (const QString& line : lines) {
d->m_currentText += line;
if (line.indexOf(newLineRegExp) != -1) {
++d->m_currentLine;
......
......@@ -115,8 +115,10 @@ void AbstractNavigationWidget::initBrowser(int height)
d->anchorClicked(url);
});
foreach (QWidget* w, findChildren<QWidget*>())
const auto childWidgets = findChildren<QWidget*>();
for (QWidget* w : childWidgets) {
w->setContextMenuPolicy(Qt::NoContextMenu);
}
}
AbstractNavigationWidget::~AbstractNavigationWidget()
......
......@@ -206,7 +206,8 @@ void ProblemNavigationContext::html(IProblem::Ptr problem)
const int startIndex = m_assistantsActions.size();
int currentIndex = startIndex;
foreach (auto assistantAction, assistant->actions()) {
const auto assistantActions = assistant->actions();
for (auto& assistantAction : assistantActions) {
m_assistantsActions.append(assistantAction);
if (currentIndex != startIndex)
......@@ -232,7 +233,7 @@ QString ProblemNavigationContext::html(bool shorten)
m_assistantsActions.clear();
int problemIndex = 0;
foreach (auto problem, m_problems) {
for (auto& problem : qAsConst(m_problems)) {
html(problem);
if (++problemIndex != m_problems.size())
......
......@@ -65,11 +65,13 @@ void collectImporters(ImportanceChecker& checker, ParsingEnvironmentFile* curren
if (checker(current))
collected.insert(current);
foreach (const ParsingEnvironmentFilePointer& importer, current->importers())
const auto importers = current->importers();
for (const ParsingEnvironmentFilePointer& importer : importers) {
if (importer.data())
collectImporters(checker, importer.data(), visited, collected);
else
qCDebug(LANGUAGE) << "missing environment-file, strange";
}
}
///The returned set does not include the file itself
......@@ -77,7 +79,8 @@ void collectImporters(ImportanceChecker& checker, ParsingEnvironmentFile* curren
void allImportedFiles(ParsingEnvironmentFilePointer file, QSet<IndexedString>& set,
QSet<ParsingEnvironmentFilePointer>& visited)
{
foreach (const ParsingEnvironmentFilePointer& import, file->imports()) {
const auto imports = file->imports();
for (const ParsingEnvironmentFilePointer& import : imports) {
if (!import) {
qCDebug(LANGUAGE) << "warning: missing import";
continue;
......@@ -171,9 +174,9 @@ void UsesCollector::startCollecting()
///Collect all "parsed versions" or forward-declarations etc. here, into allDeclarations
QSet<IndexedDeclaration> allDeclarations;
foreach (Declaration* overload, decls) {
for (Declaration* overload : qAsConst(decls)) {
m_declarations = DUChainUtils::collectAllVersions(overload);
foreach (const IndexedDeclaration& d, m_declarations) {
for (const IndexedDeclaration& d : qAsConst(m_declarations)) {
if (!d.data() || d.data()->id() != overload->id())
continue;
allDeclarations.insert(d);
......@@ -205,7 +208,7 @@ void UsesCollector::startCollecting()
///Collect definitions for declarations
if (m_collectDefinitions) {
foreach (const IndexedDeclaration d, allDeclarations) {
for (const IndexedDeclaration d : qAsConst(allDeclarations)) {
Declaration* definition = FunctionDefinition::definition(d.data());
if (definition) {
qCDebug(LANGUAGE) << "adding definition";
......@@ -220,7 +223,7 @@ void UsesCollector::startCollecting()
QList<ReferencedTopDUContext> candidateTopContexts;
candidateTopContexts.reserve(allDeclarations.size());
m_declarations.reserve(allDeclarations.size());
foreach (const IndexedDeclaration d, allDeclarations) {
for (const IndexedDeclaration d : qAsConst(allDeclarations)) {
m_declarations << d;
m_declarationTopContexts.insert(d.indexedTopContext());
//We only collect declarations with the same type here..
......@@ -238,7 +241,7 @@ void UsesCollector::startCollecting()
///to loading a whole TopDUContext.
if (decl->inSymbolTable()) {
//The declaration can only be used from other contexts if it is in the symbol table
foreach (const ReferencedTopDUContext& top, candidateTopContexts) {
for (const ReferencedTopDUContext& top : qAsConst(candidateTopContexts)) {
if (top->parsingEnvironmentFile()) {
collectImporters(checker, top->parsingEnvironmentFile().data(), visited, collected);
//In C++, visibility is not handled strictly through the import-structure.
......@@ -264,7 +267,7 @@ void UsesCollector::startCollecting()
QSet<ParsingEnvironmentFile*> filteredCollected;
QMap<IndexedString, bool> grepCache;
// Filter the collected files by performing a grep
foreach (ParsingEnvironmentFile* file, collected) {
for (ParsingEnvironmentFile* file : qAsConst(collected)) {
IndexedString url = file->url();
QMap<IndexedString, bool>::iterator grepCacheIt = grepCache.find(url);
if (grepCacheIt == grepCache.end()) {
......@@ -287,7 +290,7 @@ void UsesCollector::startCollecting()
///update the "root" top-contexts that open the whole set with their imports.
QSet<IndexedString> rootFiles;
QSet<IndexedString> allFiles;
foreach (ParsingEnvironmentFile* importer, collected) {
for (ParsingEnvironmentFile* importer : qAsConst(collected)) {
QSet<IndexedString> allImports;
QSet<ParsingEnvironmentFilePointer> visited;
allImportedFiles(ParsingEnvironmentFilePointer(importer), allImports, visited);
......@@ -304,17 +307,20 @@ void UsesCollector::startCollecting()
//If we used the AllDeclarationsContextsAndUsesRecursive flag here, we would compute way too much. This way we only
//set the minimum-features selectively on the files we really require them on.
foreach (ParsingEnvironmentFile* file, collected)
for (ParsingEnvironmentFile* file : qAsConst(collected)) {
m_staticFeaturesManipulated.insert(file->url());
}
m_staticFeaturesManipulated.insert(decl->url());
foreach (const IndexedString& file, m_staticFeaturesManipulated)
const auto currentFeaturesManipulated = m_staticFeaturesManipulated;
for (const IndexedString& file : currentFeaturesManipulated) {
ParseJob::setStaticMinimumFeatures(file, TopDUContext::AllDeclarationsContextsAndUses);
}
m_waitForUpdate = rootFiles;
foreach (const IndexedString& file, rootFiles) {
for (const IndexedString& file : qAsConst(rootFiles)) {
qCDebug(LANGUAGE) << "updating root file:" << file.str();
DUChain::self()->updateContextForUrl(file, TopDUContext::AllDeclarationsContextsAndUses, this);
}
......@@ -341,8 +347,10 @@ UsesCollector::~UsesCollector()
{
ICore::self()->languageController()->backgroundParser()->revertAllRequests(this);
foreach (const IndexedString& file, m_staticFeaturesManipulated)
const auto currentFeaturesManipulated = m_staticFeaturesManipulated;
for (const IndexedString& file : currentFeaturesManipulated) {
ParseJob::unsetStaticMinimumFeatures(file, TopDUContext::AllDeclarationsContextsAndUses);
}
}
void UsesCollector::progress(uint processed, uint total)
......@@ -360,7 +368,8 @@ void UsesCollector::updateReady(const KDevelop::IndexedString& url, KDevelop::Re
} else {
if (topContext->parsingEnvironmentFile() && topContext->parsingEnvironmentFile()->isProxyContext()) {
///Use the attached content-context instead
foreach (const DUContext::Import& import, topContext->importedParentContexts()) {
const auto importedParentContexts = topContext->importedParentContexts();
for (const DUContext::Import& import : importedParentContexts) {
if (import.context(nullptr) && import.context(nullptr)->topContext()->parsingEnvironmentFile() &&
!import.context(nullptr)->topContext()->parsingEnvironmentFile()->isProxyContext()) {
if ((import.context(nullptr)->topContext()->features() &
......@@ -450,11 +459,13 @@ void UsesCollector::updateReady(const KDevelop::IndexedString& url, KDevelop::Re
QList<KDevelop::ReferencedTopDUContext> imports;
foreach (const DUContext::Import& imported, topContext->importedParentContexts())
const auto importedParentContexts = topContext->importedParentContexts();
for (const DUContext::Import& imported : importedParentContexts) {
if (imported.context(nullptr) && imported.context(nullptr)->topContext())
imports << KDevelop::ReferencedTopDUContext(imported.context(nullptr)->topContext());
}
foreach (const KDevelop::ReferencedTopDUContext& import, imports) {
for (const KDevelop::ReferencedTopDUContext& import : qAsConst(imports)) {
IndexedString url = import->url();
lock.unlock();
updateReady(url, import);
......
......@@ -310,8 +310,8 @@ NavigatableWidgetList::NavigatableWidgetList(bool allowScrolling, uint maxHeight
void NavigatableWidgetList::deleteItems()
{
foreach (QWidget* item, items())
delete item;
const auto items = this->items();
qDeleteAll(items);
}
void NavigatableWidgetList::addItem(QWidget* widget, int pos)
......@@ -370,9 +370,11 @@ uint countUses(int usedDeclarationIndex, DUContext* context)
if (context->uses()[useIndex].m_declarationIndex == usedDeclarationIndex)
++ret;
foreach (DUContext* child, context->childContexts())
const auto childContexts = context->childContexts();
for (DUContext* child : childContexts) {
if (!isNewGroup(context, child))
ret += countUses(usedDeclarationIndex, child);
}
return ret;
}
......@@ -389,9 +391,11 @@ QList<OneUseWidget*> createUseWidgets(const CodeRepresentation& code, int usedDe
new OneUseWidget(decl, context->url(), context->transformFromLocalRevision(
context->uses()[useIndex].m_range), code);
foreach (DUContext* child, context->childContexts())
const auto childContexts = context->childContexts();
for (DUContext* child : childContexts) {
if (!isNewGroup(context, child))
ret += createUseWidgets(code, usedDeclarationIndex, decl, child);
}
return ret;
}
......@@ -426,8 +430,10 @@ ContextUsesWidget::ContextUsesWidget(const CodeRepresentation& code, const QList
hadIndices.insert(usedDeclarationIndex);
if (usedDeclarationIndex != std::numeric_limits<int>::max()) {
foreach (OneUseWidget* widget, createUseWidgets(code, usedDeclarationIndex, usedDeclaration, ctx))
const auto useWidgets = createUseWidgets(code, usedDeclarationIndex, usedDeclaration, ctx);
for (OneUseWidget* widget : useWidgets) {
addItem(widget);
}
}
}
}
......@@ -531,8 +537,10 @@ QList<ContextUsesWidget*> buildContextUses(const CodeRepresentation& code,
delete created;
}
foreach (DUContext* child, context->childContexts())
const auto childContexts = context->childContexts();
for (DUContext* child : childContexts) {
ret += buildContextUses(code, declarations, child);
}
return ret;
}
......@@ -556,13 +564,14 @@ void TopContextUsesWidget::setExpanded(bool expanded)
setUpdatesEnabled(false);
IndexedTopDUContext localTopContext(topContext);
foreach (const IndexedDeclaration& decl, m_allDeclarations) {
for (const IndexedDeclaration& decl : qAsConst(m_allDeclarations)) {
if (decl.indexedTopContext() == localTopContext) {
addItem(new DeclarationWidget(*code, decl));
}
}
foreach (ContextUsesWidget* usesWidget, buildContextUses(*code, m_allDeclarations, topContext)) {
const auto contextUseWidgets = buildContextUses(*code, m_allDeclarations, topContext);
for (ContextUsesWidget* usesWidget : contextUseWidgets) {
addItem(usesWidget);
}
......@@ -635,7 +644,8 @@ const QString UsesWidget::headerLineText() const
unsigned int UsesWidget::countAllUses() const
{
unsigned int totalUses = 0;
foreach (QWidget* w, items()) {
const auto items = this->items();
for (QWidget* w : items) {
if (auto* useWidget = qobject_cast<TopContextUsesWidget*>(w)) {
totalUses += useWidget->usesCount();
}
......@@ -646,7 +656,8 @@ unsigned int UsesWidget::countAllUses() const
void UsesWidget::setAllExpanded(bool expanded)
{
foreach (QWidget* w, items()) {
const auto items = this->items();
for (QWidget* w : items) {
if (auto* useWidget = qobject_cast<TopContextUsesWidget*>(w)) {
useWidget->setExpanded(expanded);
}
......
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