From b0b105d5758e85d08057edc2e914a7f2060bfe3f Mon Sep 17 00:00:00 2001
From: hjk <qtc-committer@nokia.com>
Date: Tue, 24 Jan 2012 18:57:39 +0100
Subject: [PATCH] ProjectExplorer: make currentProject static

This saves one function call compared to the instance()->currentProject()
pattern and is typically less to type on the caller site.

Change-Id: I65568f30205fc90e2aaca7e8e7f0192241df8c85
Reviewed-by: Daniel Teske <daniel.teske@nokia.com>
---
 .../cmakeprojectmanager.cpp                   |  2 +-
 src/plugins/cppeditor/cppeditor.cpp           |  2 +-
 src/plugins/cpptools/cpptoolsplugin.cpp       |  4 +---
 src/plugins/debugger/debuggerplugin.cpp       |  2 +-
 .../projectexplorer/currentprojectfind.cpp    | 11 +++++-----
 .../projectexplorer/projectexplorer.cpp       |  9 +++++----
 src/plugins/projectexplorer/projectexplorer.h |  2 +-
 .../projectexplorer/projecttreewidget.cpp     |  4 ++--
 src/plugins/projectexplorer/session.cpp       |  4 ++--
 .../qt4projectmanager/qt4projectmanager.cpp   |  2 +-
 src/plugins/tasklist/taskfilefactory.cpp      |  3 +--
 src/plugins/valgrind/callgrindtool.cpp        |  3 +--
 src/plugins/vcsbase/vcsbaseplugin.cpp         |  5 ++---
 src/plugins/vcsbase/vcsbasesubmiteditor.cpp   | 20 +++++++++----------
 14 files changed, 34 insertions(+), 39 deletions(-)

diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp
index a960a4fe04c..43a270f1f3a 100644
--- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp
+++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp
@@ -101,7 +101,7 @@ void CMakeManager::updateContextMenu(ProjectExplorer::Project *project, ProjectE
 
 void CMakeManager::runCMake()
 {
-    runCMake(ProjectExplorer::ProjectExplorerPlugin::instance()->currentProject());
+    runCMake(ProjectExplorer::ProjectExplorerPlugin::currentProject());
 }
 
 void CMakeManager::runCMakeContextMenu()
diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp
index 34c44ec6ce1..c54f2ac5a06 100644
--- a/src/plugins/cppeditor/cppeditor.cpp
+++ b/src/plugins/cppeditor/cppeditor.cpp
@@ -2157,7 +2157,7 @@ TextEditor::IAssistInterface *CPPEditorWidget::createAssistInterface(
         QStringList includePaths;
         QStringList frameworkPaths;
         if (ProjectExplorer::Project *project =
-                ProjectExplorer::ProjectExplorerPlugin::instance()->currentProject()) {
+                ProjectExplorer::ProjectExplorerPlugin::currentProject()) {
             includePaths = m_modelManager->projectInfo(project).includePaths;
             frameworkPaths = m_modelManager->projectInfo(project).frameworkPaths;
         }
diff --git a/src/plugins/cpptools/cpptoolsplugin.cpp b/src/plugins/cpptools/cpptoolsplugin.cpp
index 7c686adaaef..8adc6f9f1c0 100644
--- a/src/plugins/cpptools/cpptoolsplugin.cpp
+++ b/src/plugins/cpptools/cpptoolsplugin.cpp
@@ -266,9 +266,7 @@ QString CppToolsPlugin::correspondingHeaderOrSourceI(const QString &fileName) co
         return m_headerSourceMapping.value(fi.absoluteFilePath());
 
     const Core::MimeDatabase *mimeDatase = Core::ICore::mimeDatabase();
-    ProjectExplorer::ProjectExplorerPlugin *explorer =
-       ProjectExplorer::ProjectExplorerPlugin::instance();
-    ProjectExplorer::Project *project = (explorer ? explorer->currentProject() : 0);
+    ProjectExplorer::Project *project = ProjectExplorer::ProjectExplorerPlugin::currentProject();
 
     const FileType type = fileType(mimeDatase, fi);
 
diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp
index b58a2ac49d4..f95f953bbdc 100644
--- a/src/plugins/debugger/debuggerplugin.cpp
+++ b/src/plugins/debugger/debuggerplugin.cpp
@@ -499,7 +499,7 @@ public:
 bool DummyEngine::hasCapability(unsigned cap) const
 {
     // This can only be a first approximation of what to expect when running.
-    Project *project = ProjectExplorerPlugin::instance()->currentProject();
+    Project *project = ProjectExplorerPlugin::currentProject();
     if (!project)
         return 0;
     Target *target = project->activeTarget();
diff --git a/src/plugins/projectexplorer/currentprojectfind.cpp b/src/plugins/projectexplorer/currentprojectfind.cpp
index 4ebe27cc688..ab700c6c1aa 100644
--- a/src/plugins/projectexplorer/currentprojectfind.cpp
+++ b/src/plugins/projectexplorer/currentprojectfind.cpp
@@ -69,13 +69,14 @@ QString CurrentProjectFind::displayName() const
 
 bool CurrentProjectFind::isEnabled() const
 {
-    return m_plugin->currentProject() != 0 && BaseFileFind::isEnabled();
+    return ProjectExplorerPlugin::currentProject() != 0 && BaseFileFind::isEnabled();
 }
 
 QVariant CurrentProjectFind::additionalParameters() const
 {
-    if (m_plugin->currentProject() && m_plugin->currentProject()->file())
-        return qVariantFromValue(m_plugin->currentProject()->file()->fileName());
+    Project *project = ProjectExplorerPlugin::currentProject();
+    if (project && project->file())
+        return qVariantFromValue(project->file()->fileName());
     return QVariant();
 }
 
@@ -95,8 +96,8 @@ Utils::FileIterator *CurrentProjectFind::files(const QStringList &nameFilters,
 
 QString CurrentProjectFind::label() const
 {
-    QTC_ASSERT(m_plugin->currentProject(), return QString());
-    return tr("Project '%1':").arg(m_plugin->currentProject()->displayName());
+    QTC_ASSERT(ProjectExplorerPlugin::currentProject(), return QString());
+    return tr("Project '%1':").arg(ProjectExplorerPlugin::currentProject()->displayName());
 }
 
 void CurrentProjectFind::handleProjectChanged()
diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp
index ac1fc6508d7..8ea8ee1978c 100644
--- a/src/plugins/projectexplorer/projectexplorer.cpp
+++ b/src/plugins/projectexplorer/projectexplorer.cpp
@@ -1347,15 +1347,16 @@ QList<Project *> ProjectExplorerPlugin::openProjects(const QStringList &fileName
     return openedPro;
 }
 
-Project *ProjectExplorerPlugin::currentProject() const
+Project *ProjectExplorerPlugin::currentProject()
 {
+    Project *project = m_instance->d->m_currentProject;
     if (debug) {
-        if (d->m_currentProject)
-            qDebug() << "ProjectExplorerPlugin::currentProject returns " << d->m_currentProject->displayName();
+        if (project)
+            qDebug() << "ProjectExplorerPlugin::currentProject returns " << project->displayName();
         else
             qDebug() << "ProjectExplorerPlugin::currentProject returns 0";
     }
-    return d->m_currentProject;
+    return project;
 }
 
 Node *ProjectExplorerPlugin::currentNode() const
diff --git a/src/plugins/projectexplorer/projectexplorer.h b/src/plugins/projectexplorer/projectexplorer.h
index faf9167e817..6818c78502d 100644
--- a/src/plugins/projectexplorer/projectexplorer.h
+++ b/src/plugins/projectexplorer/projectexplorer.h
@@ -84,7 +84,7 @@ public:
 
     SessionManager *session() const;
 
-    Project *currentProject() const;
+    static Project *currentProject();
     Node *currentNode() const;
 
     void setCurrentFile(Project *project, const QString &file);
diff --git a/src/plugins/projectexplorer/projecttreewidget.cpp b/src/plugins/projectexplorer/projecttreewidget.cpp
index f70507f9ef0..9d5929cb481 100644
--- a/src/plugins/projectexplorer/projecttreewidget.cpp
+++ b/src/plugins/projectexplorer/projecttreewidget.cpp
@@ -263,7 +263,7 @@ void ProjectTreeWidget::setAutoSynchronization(bool sync, bool syncNow)
         connect(m_explorer, SIGNAL(currentNodeChanged(ProjectExplorer::Node*, ProjectExplorer::Project*)),
                 this, SLOT(setCurrentItem(ProjectExplorer::Node*, ProjectExplorer::Project*)));
         if (syncNow)
-            setCurrentItem(m_explorer->currentNode(), m_explorer->currentProject());
+            setCurrentItem(m_explorer->currentNode(), ProjectExplorerPlugin::currentProject());
     } else {
         disconnect(m_explorer, SIGNAL(currentNodeChanged(ProjectExplorer::Node*, ProjectExplorer::Project*)),
                 this, SLOT(setCurrentItem(ProjectExplorer::Node*, ProjectExplorer::Project*)));
@@ -354,7 +354,7 @@ void ProjectTreeWidget::initView()
     for (int i = 0; i < m_model->rowCount(sessionIndex); ++i)
         m_view->expand(m_model->index(i, 0, sessionIndex));
 
-    setCurrentItem(m_explorer->currentNode(), m_explorer->currentProject());
+    setCurrentItem(m_explorer->currentNode(), ProjectExplorerPlugin::currentProject());
 }
 
 void ProjectTreeWidget::openItem(const QModelIndex &mainIndex)
diff --git a/src/plugins/projectexplorer/session.cpp b/src/plugins/projectexplorer/session.cpp
index 3f334fd7a8f..e035ce703a1 100644
--- a/src/plugins/projectexplorer/session.cpp
+++ b/src/plugins/projectexplorer/session.cpp
@@ -820,7 +820,7 @@ Project *SessionManager::projectForFile(const QString &fileName) const
     const QList<Project *> &projectList = projects();
 
     // Check current project first
-    Project *currentProject = ProjectExplorerPlugin::instance()->currentProject();
+    Project *currentProject = ProjectExplorerPlugin::currentProject();
     if (currentProject && projectContainsFile(currentProject, fileName))
         return currentProject;
 
@@ -856,7 +856,7 @@ QString SessionManager::currentSession() const
 void SessionManager::updateWindowTitle()
 {
     if (isDefaultSession(m_sessionName)) {
-        if (Project *currentProject = ProjectExplorerPlugin::instance()->currentProject())
+        if (Project *currentProject = ProjectExplorerPlugin::currentProject())
             ICore::editorManager()->setWindowTitleAddition(currentProject->displayName());
         else
             ICore::editorManager()->setWindowTitleAddition(QString());
diff --git a/src/plugins/qt4projectmanager/qt4projectmanager.cpp b/src/plugins/qt4projectmanager/qt4projectmanager.cpp
index 94df655a5f1..eeea3fe7f34 100644
--- a/src/plugins/qt4projectmanager/qt4projectmanager.cpp
+++ b/src/plugins/qt4projectmanager/qt4projectmanager.cpp
@@ -185,7 +185,7 @@ void Qt4Manager::editorAboutToClose(Core::IEditor *editor)
 void Qt4Manager::updateVariable(const QByteArray &variable)
 {
     if (variable == kInstallBins) {
-        Qt4Project *qt4pro = qobject_cast<Qt4Project *>(projectExplorer()->currentProject());
+        Qt4Project *qt4pro = qobject_cast<Qt4Project *>(ProjectExplorer::ProjectExplorerPlugin::currentProject());
         if (!qt4pro) {
             Core::VariableManager::instance()->remove(kInstallBins);
             return;
diff --git a/src/plugins/tasklist/taskfilefactory.cpp b/src/plugins/tasklist/taskfilefactory.cpp
index d63ed182b11..a0cb3195a93 100644
--- a/src/plugins/tasklist/taskfilefactory.cpp
+++ b/src/plugins/tasklist/taskfilefactory.cpp
@@ -73,8 +73,7 @@ QString TaskFileFactory::displayName() const
 
 Core::IFile *TaskFileFactory::open(const QString &fileName)
 {
-    ProjectExplorer::Project * context =
-        ProjectExplorer::ProjectExplorerPlugin::instance()->currentProject();
+    ProjectExplorer::Project *context = ProjectExplorer::ProjectExplorerPlugin::currentProject();
     return open(context, fileName);
 }
 
diff --git a/src/plugins/valgrind/callgrindtool.cpp b/src/plugins/valgrind/callgrindtool.cpp
index f3ecd8a2405..57fdecb5cfb 100644
--- a/src/plugins/valgrind/callgrindtool.cpp
+++ b/src/plugins/valgrind/callgrindtool.cpp
@@ -398,8 +398,7 @@ void CallgrindToolPrivate::updateCostFormat()
 
 void CallgrindToolPrivate::handleFilterProjectCosts()
 {
-    ProjectExplorer::ProjectExplorerPlugin *pe = ProjectExplorer::ProjectExplorerPlugin::instance();
-    ProjectExplorer::Project *pro = pe->currentProject();
+    ProjectExplorer::Project *pro = ProjectExplorer::ProjectExplorerPlugin::currentProject();
     QTC_ASSERT(pro, return)
 
     if (m_filterProjectCosts->isChecked()) {
diff --git a/src/plugins/vcsbase/vcsbaseplugin.cpp b/src/plugins/vcsbase/vcsbaseplugin.cpp
index b4670ffba71..7e422dc87e2 100644
--- a/src/plugins/vcsbase/vcsbaseplugin.cpp
+++ b/src/plugins/vcsbase/vcsbaseplugin.cpp
@@ -231,7 +231,6 @@ static inline QString displayNameOfEditor(const QString &fileName)
 
 void StateListener::slotStateChanged()
 {
-    const ProjectExplorer::ProjectExplorerPlugin *pe = ProjectExplorer::ProjectExplorerPlugin::instance();
     Core::VcsManager *vcsManager = Core::ICore::vcsManager();
 
     // Get the current file. Are we on a temporary submit editor indicated by
@@ -280,7 +279,7 @@ void StateListener::slotStateChanged()
     }
     // Check for project, find the control
     Core::IVersionControl *projectControl = 0;
-    if (const ProjectExplorer::Project *currentProject = pe->currentProject()) {
+    if (const ProjectExplorer::Project *currentProject = ProjectExplorer::ProjectExplorerPlugin::currentProject()) {
         state.currentProjectPath = currentProject->projectDirectory();
         state.currentProjectName = currentProject->displayName();
         projectControl = vcsManager->findVersionControlForDirectory(state.currentProjectPath,
@@ -643,7 +642,7 @@ void VcsBasePlugin::createRepository()
     QTC_ASSERT(d->m_versionControl->supportsOperation(Core::IVersionControl::CreateRepositoryOperation), return);
     // Find current starting directory
     QString directory;
-    if (const ProjectExplorer::Project *currentProject = ProjectExplorer::ProjectExplorerPlugin::instance()->currentProject())
+    if (const ProjectExplorer::Project *currentProject = ProjectExplorer::ProjectExplorerPlugin::currentProject())
         directory = QFileInfo(currentProject->file()->fileName()).absolutePath();
     // Prompt for a directory that is not under version control yet
     QMainWindow *mw = Core::ICore::mainWindow();
diff --git a/src/plugins/vcsbase/vcsbasesubmiteditor.cpp b/src/plugins/vcsbase/vcsbasesubmiteditor.cpp
index e0362d00353..1570f365af2 100644
--- a/src/plugins/vcsbase/vcsbasesubmiteditor.cpp
+++ b/src/plugins/vcsbase/vcsbasesubmiteditor.cpp
@@ -770,18 +770,16 @@ QStringList VcsBaseSubmitEditor::currentProjectFiles(bool nativeSeparators, QStr
     if (name)
         name->clear();
 
-    if (ProjectExplorer::ProjectExplorerPlugin *pe = ProjectExplorer::ProjectExplorerPlugin::instance()) {
-        if (const ProjectExplorer::Project *currentProject = pe->currentProject()) {
-            QStringList files = currentProject->files(ProjectExplorer::Project::ExcludeGeneratedFiles);
-            if (name)
-                *name = currentProject->displayName();
-            if (nativeSeparators && !files.empty()) {
-                const QStringList::iterator end = files.end();
-                for (QStringList::iterator it = files.begin(); it != end; ++it)
-                    *it = QDir::toNativeSeparators(*it);
-            }
-            return files;
+    if (const ProjectExplorer::Project *currentProject = ProjectExplorer::ProjectExplorerPlugin::currentProject()) {
+        QStringList files = currentProject->files(ProjectExplorer::Project::ExcludeGeneratedFiles);
+        if (name)
+            *name = currentProject->displayName();
+        if (nativeSeparators && !files.empty()) {
+            const QStringList::iterator end = files.end();
+            for (QStringList::iterator it = files.begin(); it != end; ++it)
+                *it = QDir::toNativeSeparators(*it);
         }
+        return files;
     }
     return QStringList();
 }
-- 
GitLab