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

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

parent 1f1dcb77
......@@ -61,7 +61,8 @@ void AllClassesFolder::populateNode()
&AllClassesFolder::projectClosing);
// Parse each existing project file
foreach (IProject* project, ICore::self()->projectController()->projects()) {
const auto projects = ICore::self()->projectController()->projects();
for (IProject* project : projects) {
projectOpened(project);
}
}
......@@ -69,15 +70,19 @@ void AllClassesFolder::populateNode()
void AllClassesFolder::projectClosing(KDevelop::IProject* project)
{
// Run over all the files in the project.
foreach (const IndexedString& file, project->fileSet())
const auto files = project->fileSet();
for (const IndexedString& file : files) {
closeDocument(file);
}
}
void AllClassesFolder::projectOpened(KDevelop::IProject* project)
{
// Run over all the files in the project.
foreach (const IndexedString& file, project->fileSet())
const auto files = project->fileSet();
for (const IndexedString& file : files) {
parseDocument(file);
}
recursiveSort();
}
......
......@@ -61,7 +61,8 @@ ClassModel::ClassModel()
connect(ICore::self()->projectController(), &IProjectController::projectOpened,
this, &ClassModel::addProjectNode);
foreach (IProject* project, ICore::self()->projectController()->projects()) {
const auto projects = ICore::self()->projectController()->projects();
for (IProject* project : projects) {
addProjectNode(project);
}
}
......@@ -74,7 +75,7 @@ ClassModel::~ClassModel()
void ClassModel::updateFilterString(const QString& a_newFilterString)
{
m_allClassesNode->updateFilterString(a_newFilterString);
foreach (ClassModelNodes::FilteredProjectFolder* folder, m_projectNodes) {
for (ClassModelNodes::FilteredProjectFolder* folder : qAsConst(m_projectNodes)) {
folder->updateFilterString(a_newFilterString);
}
}
......
......@@ -111,9 +111,12 @@ void EnumNode::populateNode()
Declaration* decl = declaration();
if (decl->internalContext())
foreach (Declaration* enumDecl, decl->internalContext()->localDeclarations())
if (decl->internalContext()) {
const auto localDeclarations = decl->internalContext()->localDeclarations();
for (Declaration* enumDecl : localDeclarations) {
addNode(new EnumNode(enumDecl, m_model));
}
}
}
//////////////////////////////////////////////////////////////////////////////
......@@ -161,7 +164,8 @@ bool ClassNode::updateClassDeclarations()
auto* klass = dynamic_cast<ClassDeclaration*>(declaration());
if (klass) {
foreach (Declaration* decl, klass->internalContext()->localDeclarations()) {
const auto localDeclarations = klass->internalContext()->localDeclarations();
for (Declaration* decl : localDeclarations) {
// Ignore forward declarations.
if (decl->isForwardDeclaration())
continue;
......@@ -259,7 +263,7 @@ ClassNode* ClassNode::findSubClass(const KDevelop::IndexedQualifiedIdentifier& a
/// @todo This is slow - we go over all the sub identifiers but the assumption is that
/// this function call is rare and the list is not that long.
foreach (Node* item, m_subIdentifiers) {
for (Node* item : qAsConst(m_subIdentifiers)) {
auto* classNode = dynamic_cast<ClassNode*>(item);
if (classNode == nullptr)
continue;
......@@ -374,7 +378,8 @@ void BaseClassesFolderNode::populateNode()
// I use the imports instead of the baseClasses in the ClassDeclaration because I need
// to get to the base class identifier which is not directly accessible through the
// baseClasses function.
foreach (const DUContext::Import& import, klass->internalContext()->importedParentContexts()) {
const auto imports = klass->internalContext()->importedParentContexts();
for (const DUContext::Import& import : imports) {
DUContext* baseContext = import.context(klass->topContext());
if (baseContext && baseContext->type() == DUContext::Class) {
Declaration* baseClassDeclaration = baseContext->owner();
......@@ -473,8 +478,9 @@ void Node::recursiveSortInternal()
std::sort(m_children.begin(), m_children.end(), SortNodesFunctor());
// Tell each node to sort it self.
foreach (Node* node, m_children)
for (Node* node : qAsConst(m_children)) {
node->recursiveSortInternal();
}
}
void Node::recursiveSort()
......
......@@ -64,10 +64,13 @@ void ClassModelNodesController::unregisterForChanges(const KDevelop::IndexedStri
void ClassModelNodesController::updateChangedFiles()
{
// re-parse changed documents.
foreach (const IndexedString& file, m_updatedFiles)
foreach (ClassModelNodeDocumentChangedInterface* value, m_filesMap.values(file)) {
// TODO: m_updatedFiles seems no longer set, check again and remove if
for (const IndexedString& file : qAsConst(m_updatedFiles)) {
const auto values = m_filesMap.values(file);
for (ClassModelNodeDocumentChangedInterface* value : values) {
value->documentChanged(file);
}
}
// Processed all files.
m_updatedFiles.clear();
......
......@@ -97,7 +97,8 @@ void DocumentClassesFolder::updateChangedFiles()
bool hadChanges = false;
// re-parse changed documents.
foreach (const IndexedString& file, m_updatedFiles) {
// TODO: m_updatedFiles seems no longer set, check again and remove if
for (const IndexedString& file : qAsConst(m_updatedFiles)) {
// Make sure it's one of the monitored files.
if (m_openFiles.contains(file))
hadChanges |= updateDocument(file);
......@@ -339,11 +340,12 @@ bool DocumentClassesFolder::updateDocument(const KDevelop::IndexedString& a_file
// We need this because when a file gets unloaded, we unload the declared classes in it
// and if a namespace has no class in it, it'll forever exist and no one will remove it
// from the children list.
foreach (const QualifiedIdentifier& id, declaredNamespaces)
for (const QualifiedIdentifier& id : qAsConst(declaredNamespaces)) {
removeEmptyNamespace(id);
}
// Clear erased classes.
foreach (const FileIterator item, removedClasses) {
for (const FileIterator item : qAsConst(removedClasses)) {
if (item->nodeItem)
removeClassNode(item->nodeItem);
m_openFilesClasses.get<FileIndex>().erase(item);
......
......@@ -40,7 +40,8 @@ ProjectFolder::ProjectFolder(NodesModelInterface* a_model)
void ProjectFolder::populateNode()
{
foreach (const IndexedString& file, m_project->fileSet()) {
const auto files = m_project->fileSet();
for (const IndexedString& file : files) {
parseDocument(file);
}
......
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