diff --git a/src/plugins/clangcodemodel/clangeditordocumentparser.cpp b/src/plugins/clangcodemodel/clangeditordocumentparser.cpp index fd2c60dbaee..1f7d100fb63 100644 --- a/src/plugins/clangcodemodel/clangeditordocumentparser.cpp +++ b/src/plugins/clangcodemodel/clangeditordocumentparser.cpp @@ -88,10 +88,9 @@ ClangEditorDocumentParser::ClangEditorDocumentParser(const QString &filePath) { } -void ClangEditorDocumentParser::update(CppTools::WorkingCopy workingCopy) +void ClangEditorDocumentParser::updateHelper(CppTools::WorkingCopy workingCopy) { QTC_ASSERT(m_marker, return); - QMutexLocker locker(&m_updateIsRunning); // Determine project part State state_ = state(); diff --git a/src/plugins/clangcodemodel/clangeditordocumentparser.h b/src/plugins/clangcodemodel/clangeditordocumentparser.h index e86cf50f949..37039eb5399 100644 --- a/src/plugins/clangcodemodel/clangeditordocumentparser.h +++ b/src/plugins/clangcodemodel/clangeditordocumentparser.h @@ -46,13 +46,13 @@ class ClangEditorDocumentParser : public CppTools::BaseEditorDocumentParser public: ClangEditorDocumentParser(const QString &filePath); - void update(CppTools::WorkingCopy workingCopy) override; - QList diagnostics() const; QList ifdefedOutBlocks() const; SemanticMarker::Ptr semanticMarker() const; private: + void updateHelper(CppTools::WorkingCopy workingCopy) override; + SemanticMarker::Ptr m_marker; }; diff --git a/src/plugins/cpptools/baseeditordocumentparser.cpp b/src/plugins/cpptools/baseeditordocumentparser.cpp index 31d08bd4317..d075a86622a 100644 --- a/src/plugins/cpptools/baseeditordocumentparser.cpp +++ b/src/plugins/cpptools/baseeditordocumentparser.cpp @@ -31,6 +31,7 @@ #include "baseeditordocumentparser.h" #include "baseeditordocumentprocessor.h" +#include "cppworkingcopy.h" #include "editordocumenthandle.h" namespace CppTools { @@ -44,14 +45,13 @@ namespace CppTools { It's meant to be used in the C++ editor to get precise results by using the "best" project part for a file. - Derived classes are expected to implement update() this way: + Derived classes are expected to implement updateHelper() this way: \list \li Get a copy of the configuration and the last state. - \li Acquire the protected m_updateIsRunning for the duration of update(). \li Work on the data and do whatever is necessary. At least, update the project part with the help of determineProjectPart(). - \li Ensure the new state is set before update() returns. + \li Ensure the new state is set before updateHelper() returns. \endlist */ @@ -81,6 +81,12 @@ void BaseEditorDocumentParser::setConfiguration(const Configuration &configurati m_configuration = configuration; } +void BaseEditorDocumentParser::update(WorkingCopy workingCopy) +{ + QMutexLocker locker(&m_updateIsRunning); + updateHelper(workingCopy); +} + BaseEditorDocumentParser::State BaseEditorDocumentParser::state() const { QMutexLocker locker(&m_stateAndConfigurationMutex); diff --git a/src/plugins/cpptools/baseeditordocumentparser.h b/src/plugins/cpptools/baseeditordocumentparser.h index 42ce6c12b33..c5a19748118 100644 --- a/src/plugins/cpptools/baseeditordocumentparser.h +++ b/src/plugins/cpptools/baseeditordocumentparser.h @@ -56,11 +56,10 @@ public: virtual ~BaseEditorDocumentParser(); QString filePath() const; - Configuration configuration() const; void setConfiguration(const Configuration &configuration); - virtual void update(WorkingCopy workingCopy) = 0; + void update(WorkingCopy workingCopy); ProjectPart::Ptr projectPart() const; @@ -69,7 +68,6 @@ protected: QByteArray editorDefines; ProjectPart::Ptr projectPart; }; - State state() const; void setState(const State &state); @@ -77,14 +75,15 @@ protected: const Configuration &config, const State &state); - mutable QMutex m_updateIsRunning; mutable QMutex m_stateAndConfigurationMutex; private: - const QString m_filePath; + virtual void updateHelper(WorkingCopy workingCopy) = 0; + const QString m_filePath; Configuration m_configuration; State m_state; + mutable QMutex m_updateIsRunning; }; } // namespace CppTools diff --git a/src/plugins/cpptools/builtineditordocumentparser.cpp b/src/plugins/cpptools/builtineditordocumentparser.cpp index 3871cb2bb0b..f244595fde0 100644 --- a/src/plugins/cpptools/builtineditordocumentparser.cpp +++ b/src/plugins/cpptools/builtineditordocumentparser.cpp @@ -44,10 +44,8 @@ BuiltinEditorDocumentParser::BuiltinEditorDocumentParser(const QString &filePath qRegisterMetaType("CPlusPlus::Snapshot"); } -void BuiltinEditorDocumentParser::update(WorkingCopy workingCopy) +void BuiltinEditorDocumentParser::updateHelper(WorkingCopy workingCopy) { - QMutexLocker locker(&m_updateIsRunning); - const Configuration baseConfig = configuration(); const bool releaseSourceAndAST_ = releaseSourceAndAST(); diff --git a/src/plugins/cpptools/builtineditordocumentparser.h b/src/plugins/cpptools/builtineditordocumentparser.h index a495be4787a..fee17882eb7 100644 --- a/src/plugins/cpptools/builtineditordocumentparser.h +++ b/src/plugins/cpptools/builtineditordocumentparser.h @@ -51,8 +51,6 @@ public: bool releaseSourceAndAST() const; void setReleaseSourceAndAST(bool release); - void update(WorkingCopy workingCopy) override; - CPlusPlus::Document::Ptr document() const; CPlusPlus::Snapshot snapshot() const; ProjectPart::HeaderPaths headerPaths() const; @@ -66,6 +64,7 @@ public: static BuiltinEditorDocumentParser *get(const QString &filePath); private: + void updateHelper(WorkingCopy workingCopy) override; void addFileAndDependencies(CPlusPlus::Snapshot *snapshot, QSet *toRemove, const Utils::FileName &fileName) const; @@ -80,7 +79,6 @@ private: CPlusPlus::Snapshot snapshot; bool forceSnapshotInvalidation = false; }; - ExtraState extraState() const; void setExtraState(const ExtraState &extraState);