CppTools: Remove some duplication

Change-Id: I8c84660b28c3e76b2cedd08ff3b44a38583f38a0
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Nikolai Kosjar
2016-12-14 18:58:23 +01:00
parent 5421615070
commit bd66d5ac05
15 changed files with 59 additions and 56 deletions

View File

@@ -36,11 +36,13 @@ ClangEditorDocumentParser::ClangEditorDocumentParser(const QString &filePath)
}
void ClangEditorDocumentParser::updateImpl(const QFutureInterface<void> &,
const CppTools::WorkingCopy &,
const ProjectExplorer::Project *activeProject)
const UpdateParams &updateParams)
{
State state_ = state();
state_.projectPart = determineProjectPart(filePath(), configuration(), state_, activeProject);
state_.projectPart = determineProjectPart(filePath(),
configuration(),
state_,
updateParams.activeProject);
setState(state_);
}

View File

@@ -38,8 +38,7 @@ public:
private:
void updateImpl(const QFutureInterface<void> &future,
const CppTools::WorkingCopy &,
const ProjectExplorer::Project *activeProject) override;
const UpdateParams &updateParams) override;
};
} // namespace ClangCodeModel

View File

@@ -46,8 +46,6 @@
#include <cpptools/cppworkingcopy.h>
#include <cpptools/editordocumenthandle.h>
#include <projectexplorer/session.h>
#include <texteditor/convenience.h>
#include <texteditor/fontsettings.h>
#include <texteditor/texteditor.h>
@@ -103,7 +101,8 @@ ClangEditorDocumentProcessor::~ClangEditorDocumentProcessor()
}
}
void ClangEditorDocumentProcessor::run()
void ClangEditorDocumentProcessor::runImpl(
const CppTools::BaseEditorDocumentParser::UpdateParams &updateParams)
{
m_updateTranslationUnitTimer.start();
@@ -116,13 +115,7 @@ void ClangEditorDocumentProcessor::run()
m_parserRevision = revision();
connect(&m_parserWatcher, &QFutureWatcher<void>::finished,
this, &ClangEditorDocumentProcessor::onParserFinished);
const CppTools::WorkingCopy workingCopy = CppTools::CppModelManager::instance()->workingCopy();
const ProjectExplorer::Project *activeProject
= ProjectExplorer::SessionManager::startupProject();
const QFuture<void> future = ::Utils::runAsync(&runParser,
parser(),
workingCopy,
activeProject);
const QFuture<void> future = ::Utils::runAsync(&runParser, parser(), updateParams);
m_parserWatcher.setFuture(future);
// Run builtin processor

View File

@@ -55,7 +55,7 @@ public:
~ClangEditorDocumentProcessor();
// BaseEditorDocumentProcessor interface
void run() override;
void runImpl(const CppTools::BaseEditorDocumentParser::UpdateParams &updateParams) override;
void semanticRehighlight() override;
void recalculateSemanticInfoDetached(bool force) override;
CppTools::SemanticInfo recalculateSemanticInfo() override;

View File

@@ -77,19 +77,17 @@ void BaseEditorDocumentParser::setConfiguration(const Configuration &configurati
m_configuration = configuration;
}
void BaseEditorDocumentParser::update(const WorkingCopy &workingCopy,
const ProjectExplorer::Project *activeProject)
void BaseEditorDocumentParser::update(const UpdateParams &updateParams)
{
QFutureInterface<void> dummy;
update(dummy, workingCopy, activeProject);
update(dummy, updateParams);
}
void BaseEditorDocumentParser::update(const QFutureInterface<void> &future,
const WorkingCopy &workingCopy,
const ProjectExplorer::Project *activeProject)
const UpdateParams &updateParams)
{
QMutexLocker locker(&m_updateIsRunning);
updateImpl(future, workingCopy, activeProject);
updateImpl(future, updateParams);
}
BaseEditorDocumentParser::State BaseEditorDocumentParser::state() const

View File

@@ -52,6 +52,18 @@ public:
ProjectPart::Ptr manuallySetProjectPart;
};
struct UpdateParams {
UpdateParams(const WorkingCopy &workingCopy,
const ProjectExplorer::Project *activeProject)
: workingCopy(workingCopy)
, activeProject(activeProject)
{
}
WorkingCopy workingCopy;
const ProjectExplorer::Project *activeProject = nullptr;
};
public:
BaseEditorDocumentParser(const QString &filePath);
virtual ~BaseEditorDocumentParser();
@@ -60,11 +72,8 @@ public:
Configuration configuration() const;
void setConfiguration(const Configuration &configuration);
void update(const WorkingCopy &workingCopy,
const ProjectExplorer::Project *activeProject);
void update(const QFutureInterface<void> &future,
const WorkingCopy &workingCopy,
const ProjectExplorer::Project *activeProject);
void update(const UpdateParams &updateParams);
void update(const QFutureInterface<void> &future, const UpdateParams &updateParams);
ProjectPart::Ptr projectPart() const;
@@ -85,8 +94,7 @@ protected:
private:
virtual void updateImpl(const QFutureInterface<void> &future,
const WorkingCopy &workingCopy,
const ProjectExplorer::Project *activeProject) = 0;
const UpdateParams &updateParams) = 0;
const QString m_filePath;
Configuration m_configuration;

View File

@@ -29,6 +29,7 @@
#include "cpptoolsbridge.h"
#include "editordocumenthandle.h"
#include <projectexplorer/session.h>
#include <texteditor/quickfix.h>
namespace CppTools {
@@ -52,6 +53,12 @@ BaseEditorDocumentProcessor::~BaseEditorDocumentProcessor()
{
}
void BaseEditorDocumentProcessor::run()
{
runImpl({CppModelManager::instance()->workingCopy(),
ProjectExplorer::SessionManager::startupProject()});
}
TextEditor::QuickFixOperations
BaseEditorDocumentProcessor::extraRefactoringOperations(const TextEditor::AssistInterface &)
{
@@ -73,8 +80,7 @@ void BaseEditorDocumentProcessor::editorDocumentTimerRestarted()
void BaseEditorDocumentProcessor::runParser(QFutureInterface<void> &future,
BaseEditorDocumentParser::Ptr parser,
const WorkingCopy workingCopy,
const ProjectExplorer::Project *activeProject)
BaseEditorDocumentParser::UpdateParams updateParams)
{
future.setProgressRange(0, 1);
if (future.isCanceled()) {
@@ -82,7 +88,7 @@ void BaseEditorDocumentProcessor::runParser(QFutureInterface<void> &future,
return;
}
parser->update(future, workingCopy, activeProject);
parser->update(future, updateParams);
CppToolsBridge::finishedRefreshingSourceFiles({parser->filePath()});
future.setProgressValue(1);

View File

@@ -54,8 +54,7 @@ public:
BaseEditorDocumentProcessor(QTextDocument *textDocument, const QString &filePath);
virtual ~BaseEditorDocumentProcessor();
// Function interface to implement
virtual void run() = 0;
void run();
virtual void semanticRehighlight() = 0;
virtual void recalculateSemanticInfoDetached(bool force) = 0;
virtual CppTools::SemanticInfo recalculateSemanticInfo() = 0;
@@ -91,14 +90,16 @@ signals:
protected:
static void runParser(QFutureInterface<void> &future,
BaseEditorDocumentParser::Ptr parser,
const CppTools::WorkingCopy workingCopy,
const ProjectExplorer::Project *activeProject);
BaseEditorDocumentParser::UpdateParams updateParams);
// Convenience
QString filePath() const { return m_filePath; }
unsigned revision() const { return static_cast<unsigned>(m_textDocument->revision()); }
QTextDocument *textDocument() const { return m_textDocument; }
private:
virtual void runImpl(const BaseEditorDocumentParser::UpdateParams &updateParams) = 0;
private:
QString m_filePath;
QTextDocument *m_textDocument;

View File

@@ -56,8 +56,7 @@ BuiltinEditorDocumentParser::BuiltinEditorDocumentParser(const QString &filePath
}
void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface<void> &future,
const WorkingCopy &theWorkingCopy,
const ProjectExplorer::Project *activeProject)
const UpdateParams &updateParams)
{
if (filePath().isEmpty())
return;
@@ -67,7 +66,7 @@ void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface<void> &futur
State baseState = state();
ExtraState state = extraState();
WorkingCopy workingCopy = theWorkingCopy;
WorkingCopy workingCopy = updateParams.workingCopy;
bool invalidateSnapshot = false, invalidateConfig = false, editorDefinesChanged_ = false;
@@ -78,7 +77,10 @@ void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface<void> &futur
QString projectConfigFile;
LanguageFeatures features = LanguageFeatures::defaultFeatures();
baseState.projectPart = determineProjectPart(filePath(), baseConfig, baseState, activeProject);
baseState.projectPart = determineProjectPart(filePath(),
baseConfig,
baseState,
updateParams.activeProject);
if (state.forceSnapshotInvalidation) {
invalidateSnapshot = true;

View File

@@ -59,8 +59,7 @@ public:
private:
void updateImpl(const QFutureInterface<void> &future,
const WorkingCopy &workingCopy,
const ProjectExplorer::Project *activeProject) override;
const UpdateParams &updateParams) override;
void addFileAndDependencies(CPlusPlus::Snapshot *snapshot,
QSet<Utils::FileName> *toRemove,
const Utils::FileName &fileName) const;

View File

@@ -32,8 +32,6 @@
#include "cpptoolsreuse.h"
#include "cppworkingcopy.h"
#include <projectexplorer/session.h>
#include <texteditor/convenience.h>
#include <texteditor/fontsettings.h>
#include <texteditor/refactoroverlay.h>
@@ -204,16 +202,13 @@ BuiltinEditorDocumentProcessor::~BuiltinEditorDocumentProcessor()
m_parserFuture.waitForFinished();
}
void BuiltinEditorDocumentProcessor::run()
void BuiltinEditorDocumentProcessor::runImpl(
const BaseEditorDocumentParser::UpdateParams &updateParams)
{
CppModelManager *mgr = CppModelManager::instance();
const ProjectExplorer::Project *activeProject
= ProjectExplorer::SessionManager::startupProject();
m_parserFuture = Utils::runAsync(mgr->sharedThreadPool(),
m_parserFuture = Utils::runAsync(CppModelManager::instance()->sharedThreadPool(),
runParser,
parser(),
mgr->workingCopy(),
activeProject);
updateParams);
}
BaseEditorDocumentParser::Ptr BuiltinEditorDocumentProcessor::parser()

View File

@@ -43,7 +43,7 @@ public:
~BuiltinEditorDocumentProcessor();
// BaseEditorDocumentProcessor interface
void run() override;
void runImpl(const BaseEditorDocumentParser::UpdateParams &updateParams) override;
void recalculateSemanticInfoDetached(bool force) override;
void semanticRehighlight() override;
CppTools::SemanticInfo recalculateSemanticInfo() override;

View File

@@ -158,7 +158,7 @@ void indexFindErrors(QFutureInterface<void> &future, const ParseParams params)
// Parse the file as precisely as possible
BuiltinEditorDocumentParser parser(file);
parser.setReleaseSourceAndAST(false);
parser.update(CppModelManager::instance()->workingCopy(), nullptr);
parser.update({CppModelManager::instance()->workingCopy(), nullptr});
CPlusPlus::Document::Ptr document = parser.document();
QTC_ASSERT(document, return);

View File

@@ -2122,7 +2122,7 @@ void CppCompletionAssistInterface::getCppSpecifics() const
m_gotCppSpecifics = true;
if (m_parser) {
m_parser->update(CppTools::CppModelManager::instance()->workingCopy(), nullptr);
m_parser->update({CppTools::CppModelManager::instance()->workingCopy(), nullptr});
m_snapshot = m_parser->snapshot();
m_headerPaths = m_parser->headerPaths();
}

View File

@@ -877,7 +877,7 @@ void CppToolsPlugin::test_modelmanager_precompiled_headers()
BaseEditorDocumentParser::Configuration config = parser->configuration();
config.usePrecompiledHeaders = true;
parser->setConfiguration(config);
parser->update(CppModelManager::instance()->workingCopy(), nullptr);
parser->update({CppModelManager::instance()->workingCopy(), nullptr});
// Check if defines from pch are considered
Document::Ptr document = mm->document(fileName);
@@ -955,7 +955,7 @@ void CppToolsPlugin::test_modelmanager_defines_per_editor()
BaseEditorDocumentParser::Configuration config = parser->configuration();
config.editorDefines = editorDefines.toUtf8();
parser->setConfiguration(config);
parser->update(CppModelManager::instance()->workingCopy(), nullptr);
parser->update({CppModelManager::instance()->workingCopy(), nullptr});
Document::Ptr doc = mm->document(main1File);
QCOMPARE(nameOfFirstDeclaration(doc), firstDeclarationName);