forked from qt-creator/qt-creator
CppTools: Make updateProjectPart() const
...and rename to "determineProjectPart". This is in preparation for a follow-up change. determineProjectPart() should not set any state. Change-Id: Iad7be8638fd97a79a4227a944896ac9af0a36862 Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
This commit is contained in:
@@ -94,7 +94,7 @@ void ClangEditorDocumentParser::update(CppTools::WorkingCopy workingCopy)
|
|||||||
QMutexLocker lock(m_marker->mutex());
|
QMutexLocker lock(m_marker->mutex());
|
||||||
QMutexLocker lock2(&m_mutex);
|
QMutexLocker lock2(&m_mutex);
|
||||||
|
|
||||||
updateProjectPart();
|
m_projectPart = determineProjectPart();
|
||||||
const QStringList options = createOptions(filePath(), projectPart(), true);
|
const QStringList options = createOptions(filePath(), projectPart(), true);
|
||||||
|
|
||||||
qCDebug(log, "Reparse options (cmd line equivalent): %s",
|
qCDebug(log, "Reparse options (cmd line equivalent): %s",
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace CppTools {
|
|||||||
the "best" project part for a file.
|
the "best" project part for a file.
|
||||||
|
|
||||||
Derived classes are expected to implement update() by using the protected
|
Derived classes are expected to implement update() by using the protected
|
||||||
mutex, updateProjectPart() and by respecting the options set by the client.
|
mutex, determineProjectPart() and by respecting the options set by the client.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
BaseEditorDocumentParser::BaseEditorDocumentParser(const QString &filePath)
|
BaseEditorDocumentParser::BaseEditorDocumentParser(const QString &filePath)
|
||||||
@@ -115,33 +115,35 @@ BaseEditorDocumentParser *BaseEditorDocumentParser::get(const QString &filePath)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseEditorDocumentParser::updateProjectPart()
|
ProjectPart::Ptr BaseEditorDocumentParser::determineProjectPart() const
|
||||||
{
|
{
|
||||||
if (m_manuallySetProjectPart) {
|
if (m_manuallySetProjectPart)
|
||||||
m_projectPart = m_manuallySetProjectPart;
|
return m_manuallySetProjectPart;
|
||||||
return;
|
|
||||||
}
|
ProjectPart::Ptr projectPart = m_projectPart;
|
||||||
|
|
||||||
CppModelManager *cmm = CppModelManager::instance();
|
CppModelManager *cmm = CppModelManager::instance();
|
||||||
QList<ProjectPart::Ptr> projectParts = cmm->projectPart(m_filePath);
|
QList<ProjectPart::Ptr> projectParts = cmm->projectPart(m_filePath);
|
||||||
if (projectParts.isEmpty()) {
|
if (projectParts.isEmpty()) {
|
||||||
if (m_projectPart)
|
if (projectPart)
|
||||||
// File is not directly part of any project, but we got one before. We will re-use it,
|
// File is not directly part of any project, but we got one before. We will re-use it,
|
||||||
// because re-calculating this can be expensive when the dependency table is big.
|
// because re-calculating this can be expensive when the dependency table is big.
|
||||||
return;
|
return projectPart;
|
||||||
|
|
||||||
// Fall-back step 1: Get some parts through the dependency table:
|
// Fall-back step 1: Get some parts through the dependency table:
|
||||||
projectParts = cmm->projectPartFromDependencies(Utils::FileName::fromString(m_filePath));
|
projectParts = cmm->projectPartFromDependencies(Utils::FileName::fromString(m_filePath));
|
||||||
if (projectParts.isEmpty())
|
if (projectParts.isEmpty())
|
||||||
// Fall-back step 2: Use fall-back part from the model manager:
|
// Fall-back step 2: Use fall-back part from the model manager:
|
||||||
m_projectPart = cmm->fallbackProjectPart();
|
projectPart = cmm->fallbackProjectPart();
|
||||||
else
|
else
|
||||||
m_projectPart = projectParts.first();
|
projectPart = projectParts.first();
|
||||||
} else {
|
} else {
|
||||||
if (!projectParts.contains(m_projectPart))
|
if (!projectParts.contains(projectPart))
|
||||||
// Apparently the project file changed, so update our project part.
|
// Apparently the project file changed, so update our project part.
|
||||||
m_projectPart = projectParts.first();
|
projectPart = projectParts.first();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return projectPart;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseEditorDocumentParser::editorDefinesChanged() const
|
bool BaseEditorDocumentParser::editorDefinesChanged() const
|
||||||
|
|||||||
@@ -63,18 +63,18 @@ public:
|
|||||||
static BaseEditorDocumentParser *get(const QString &filePath);
|
static BaseEditorDocumentParser *get(const QString &filePath);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void updateProjectPart();
|
ProjectPart::Ptr determineProjectPart() const;
|
||||||
|
|
||||||
bool editorDefinesChanged() const;
|
bool editorDefinesChanged() const;
|
||||||
void resetEditorDefinesChanged();
|
void resetEditorDefinesChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
mutable QMutex m_mutex;
|
mutable QMutex m_mutex;
|
||||||
|
ProjectPart::Ptr m_projectPart;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QString m_filePath;
|
const QString m_filePath;
|
||||||
|
|
||||||
ProjectPart::Ptr m_projectPart;
|
|
||||||
ProjectPart::Ptr m_manuallySetProjectPart;
|
ProjectPart::Ptr m_manuallySetProjectPart;
|
||||||
|
|
||||||
bool m_usePrecompiledHeaders;
|
bool m_usePrecompiledHeaders;
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ void BuiltinEditorDocumentParser::update(WorkingCopy workingCopy)
|
|||||||
QString projectConfigFile;
|
QString projectConfigFile;
|
||||||
LanguageFeatures features = LanguageFeatures::defaultFeatures();
|
LanguageFeatures features = LanguageFeatures::defaultFeatures();
|
||||||
|
|
||||||
updateProjectPart();
|
m_projectPart = determineProjectPart();
|
||||||
|
|
||||||
if (m_forceSnapshotInvalidation) {
|
if (m_forceSnapshotInvalidation) {
|
||||||
invalidateSnapshot = true;
|
invalidateSnapshot = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user