Commit 0df1ee1a authored by hjk's avatar hjk
Browse files

CppTools: make correspondingHeaderOrSource freely accessible



Change-Id: Ic8aba607157381359984ef1c99b2f32161daaecd
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 315a3ebd
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "cpplocatorfilter.h" #include "cpplocatorfilter.h"
#include "symbolsfindfilter.h" #include "symbolsfindfilter.h"
#include "cpptoolssettings.h" #include "cpptoolssettings.h"
#include "cpptoolsreuse.h"
#include <extensionsystem/pluginmanager.h> #include <extensionsystem/pluginmanager.h>
...@@ -74,12 +75,15 @@ ...@@ -74,12 +75,15 @@
#include <sstream> #include <sstream>
using namespace CppTools::Internal;
using namespace CPlusPlus; using namespace CPlusPlus;
namespace CppTools {
namespace Internal {
enum { debug = 0 }; enum { debug = 0 };
static CppToolsPlugin *m_instance = 0; static CppToolsPlugin *m_instance = 0;
static QHash<QString, QString> m_headerSourceMapping;
CppToolsPlugin::CppToolsPlugin() : CppToolsPlugin::CppToolsPlugin() :
m_modelManager(0), m_modelManager(0),
...@@ -250,16 +254,23 @@ static int commonStringLength(const QString &s1, const QString &s2) ...@@ -250,16 +254,23 @@ static int commonStringLength(const QString &s1, const QString &s2)
return length; return length;
} }
QString CppToolsPlugin::correspondingHeaderOrSourceI(const QString &fileName) const } // namespace Internal
QString correspondingHeaderOrSource(const QString &fileName, bool *wasHeader)
{ {
const QFileInfo fi(fileName); using namespace Internal;
if (m_headerSourceMapping.contains(fi.absoluteFilePath()))
return m_headerSourceMapping.value(fi.absoluteFilePath());
const Core::MimeDatabase *mimeDatase = Core::ICore::mimeDatabase(); const Core::MimeDatabase *mimeDatase = Core::ICore::mimeDatabase();
ProjectExplorer::Project *project = ProjectExplorer::ProjectExplorerPlugin::currentProject(); const QFileInfo fi(fileName);
if (m_headerSourceMapping.contains(fi.absoluteFilePath())) {
if (wasHeader)
*wasHeader = fileType(mimeDatase, fi) == HeaderFile;
return m_headerSourceMapping.value(fi.absoluteFilePath());
}
const FileType type = fileType(mimeDatase, fi); FileType type = fileType(mimeDatase, fi);
if (wasHeader)
*wasHeader = type == HeaderFile;
if (debug) if (debug)
qDebug() << Q_FUNC_INFO << fileName << type; qDebug() << Q_FUNC_INFO << fileName << type;
...@@ -298,6 +309,7 @@ QString CppToolsPlugin::correspondingHeaderOrSourceI(const QString &fileName) co ...@@ -298,6 +309,7 @@ QString CppToolsPlugin::correspondingHeaderOrSourceI(const QString &fileName) co
} }
// Find files in the project // Find files in the project
ProjectExplorer::Project *project = ProjectExplorer::ProjectExplorerPlugin::currentProject();
if (project) { if (project) {
QString bestFileName; QString bestFileName;
int compareValue = 0; int compareValue = 0;
...@@ -324,12 +336,6 @@ QString CppToolsPlugin::correspondingHeaderOrSourceI(const QString &fileName) co ...@@ -324,12 +336,6 @@ QString CppToolsPlugin::correspondingHeaderOrSourceI(const QString &fileName) co
return QString(); return QString();
} }
QString CppToolsPlugin::correspondingHeaderOrSource(const QString &fileName) } // namespace CppTools
{
const QString rc = m_instance->correspondingHeaderOrSourceI(fileName);
if (debug)
qDebug() << Q_FUNC_INFO << fileName << rc;
return rc;
}
Q_EXPORT_PLUGIN(CppToolsPlugin) Q_EXPORT_PLUGIN(CppTools::Internal::CppToolsPlugin)
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#ifndef CPPTOOLS_H #ifndef CPPTOOLS_H
#define CPPTOOLS_H #define CPPTOOLS_H
#include "cpptools_global.h"
#include <extensionsystem/iplugin.h> #include <extensionsystem/iplugin.h>
#include <projectexplorer/projectexplorer.h> #include <projectexplorer/projectexplorer.h>
#include <find/ifindfilter.h> #include <find/ifindfilter.h>
...@@ -70,7 +72,6 @@ public: ...@@ -70,7 +72,6 @@ public:
void extensionsInitialized(); void extensionsInitialized();
ShutdownFlag aboutToShutdown(); ShutdownFlag aboutToShutdown();
CppModelManager *cppModelManager() { return m_modelManager; } CppModelManager *cppModelManager() { return m_modelManager; }
static QString correspondingHeaderOrSource(const QString &fileName);
private slots: private slots:
void switchHeaderSource(); void switchHeaderSource();
...@@ -109,12 +110,9 @@ private: ...@@ -109,12 +110,9 @@ private:
#endif #endif
private: private:
QString correspondingHeaderOrSourceI(const QString &fileName) const;
CppModelManager *m_modelManager; CppModelManager *m_modelManager;
QSharedPointer<CppFileSettings> m_fileSettings; QSharedPointer<CppFileSettings> m_fileSettings;
CppToolsSettings *m_settings; CppToolsSettings *m_settings;
mutable QHash<QString, QString> m_headerSourceMapping;
}; };
} // namespace Internal } // namespace Internal
......
...@@ -52,6 +52,8 @@ bool CPPTOOLS_EXPORT isValidIdentifier(const QString &s); ...@@ -52,6 +52,8 @@ bool CPPTOOLS_EXPORT isValidIdentifier(const QString &s);
bool CPPTOOLS_EXPORT isQtKeyword(const QStringRef &text); bool CPPTOOLS_EXPORT isQtKeyword(const QStringRef &text);
QString CPPTOOLS_EXPORT correspondingHeaderOrSource(const QString &fileName, bool *wasHeader = 0);
} // CppTools } // CppTools
#endif // CPPTOOLSREUSE_H #endif // CPPTOOLSREUSE_H
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
** **
****************************************************************************/ ****************************************************************************/
#include "cpptoolsplugin.h" #include "cpptoolsreuse.h"
#include "cpprefactoringchanges.h" #include "cpprefactoringchanges.h"
#include "insertionpointlocator.h" #include "insertionpointlocator.h"
#include "symbolfinder.h" #include "symbolfinder.h"
...@@ -578,7 +578,7 @@ QList<InsertionLocation> InsertionPointLocator::methodDefinition( ...@@ -578,7 +578,7 @@ QList<InsertionLocation> InsertionPointLocator::methodDefinition(
declaration->fileNameLength()); declaration->fileNameLength());
QString target = declFileName; QString target = declFileName;
if (!isSourceFile(declFileName)) { if (!isSourceFile(declFileName)) {
QString candidate = Internal::CppToolsPlugin::correspondingHeaderOrSource(declFileName); QString candidate = CppTools::correspondingHeaderOrSource(declFileName);
if (!candidate.isEmpty()) if (!candidate.isEmpty())
target = candidate; target = candidate;
} }
......
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