forked from qt-creator/qt-creator
Clang: Use member instead of pointer
It makes the resource allocation much more clear. Change-Id: Ib276e089dc3db551171373d72e9b54c9d87b4c8c Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
@@ -299,10 +299,9 @@ namespace Internal {
|
||||
// -----------------------------
|
||||
// ClangCompletionAssistProvider
|
||||
// -----------------------------
|
||||
ClangCompletionAssistProvider::ClangCompletionAssistProvider(IpcCommunicator::Ptr ipcCommunicator)
|
||||
ClangCompletionAssistProvider::ClangCompletionAssistProvider(IpcCommunicator &ipcCommunicator)
|
||||
: m_ipcCommunicator(ipcCommunicator)
|
||||
{
|
||||
QTC_CHECK(m_ipcCommunicator);
|
||||
}
|
||||
|
||||
IAssistProvider::RunType ClangCompletionAssistProvider::runType() const
|
||||
@@ -642,7 +641,7 @@ const TextEditor::TextEditorWidget *ClangCompletionAssistInterface::textEditorWi
|
||||
}
|
||||
|
||||
ClangCompletionAssistInterface::ClangCompletionAssistInterface(
|
||||
IpcCommunicator::Ptr ipcCommunicator,
|
||||
IpcCommunicator &ipcCommunicator,
|
||||
const TextEditorWidget *textEditorWidget,
|
||||
int position,
|
||||
const QString &fileName,
|
||||
@@ -661,7 +660,7 @@ ClangCompletionAssistInterface::ClangCompletionAssistInterface(
|
||||
m_unsavedFiles = Utils::createUnsavedFiles(mmi->workingCopy());
|
||||
}
|
||||
|
||||
IpcCommunicator::Ptr ClangCompletionAssistInterface::ipcCommunicator() const
|
||||
IpcCommunicator &ClangCompletionAssistInterface::ipcCommunicator() const
|
||||
{
|
||||
return m_ipcCommunicator;
|
||||
}
|
||||
@@ -1111,8 +1110,8 @@ void ClangCompletionAssistProcessor::sendFileContent(const QString &projectFileP
|
||||
: modifiedFileContent;
|
||||
const bool hasUnsavedContent = true; // TODO
|
||||
|
||||
IpcCommunicator::Ptr ipcCommunicator = m_interface->ipcCommunicator();
|
||||
ipcCommunicator->registerFilesForCodeCompletion(
|
||||
IpcCommunicator &ipcCommunicator = m_interface->ipcCommunicator();
|
||||
ipcCommunicator.registerFilesForCodeCompletion(
|
||||
{FileContainer(filePath,
|
||||
projectFilePath,
|
||||
Utf8String::fromByteArray(unsavedContent),
|
||||
@@ -1129,7 +1128,7 @@ void ClangCompletionAssistProcessor::sendCompletionRequest(int position,
|
||||
const QString filePath = m_interface->fileName();
|
||||
const QString projectFilePath = Utils::projectFilePathForFile(filePath);
|
||||
sendFileContent(projectFilePath, modifiedFileContent);
|
||||
m_interface->ipcCommunicator()->completeCode(this, filePath, line, column, projectFilePath);
|
||||
m_interface->ipcCommunicator().completeCode(this, filePath, line, column, projectFilePath);
|
||||
}
|
||||
|
||||
TextEditor::IAssistProposal *ClangCompletionAssistProcessor::createProposal() const
|
||||
|
||||
@@ -60,7 +60,7 @@ class ClangCompletionAssistProvider : public CppTools::CppCompletionAssistProvid
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ClangCompletionAssistProvider(IpcCommunicator::Ptr ipcCommunicator);
|
||||
ClangCompletionAssistProvider(IpcCommunicator &ipcCommunicator);
|
||||
|
||||
IAssistProvider::RunType runType() const override;
|
||||
|
||||
@@ -73,7 +73,7 @@ public:
|
||||
TextEditor::AssistReason reason) const override;
|
||||
|
||||
private:
|
||||
IpcCommunicator::Ptr m_ipcCommunicator;
|
||||
IpcCommunicator &m_ipcCommunicator;
|
||||
};
|
||||
|
||||
class ClangAssistProposalItem : public TextEditor::AssistProposalItem
|
||||
@@ -117,7 +117,7 @@ private:
|
||||
class ClangCompletionAssistInterface: public TextEditor::AssistInterface
|
||||
{
|
||||
public:
|
||||
ClangCompletionAssistInterface(ClangCodeModel::Internal::IpcCommunicator::Ptr ipcCommunicator,
|
||||
ClangCompletionAssistInterface(ClangCodeModel::Internal::IpcCommunicator &ipcCommunicator,
|
||||
const TextEditor::TextEditorWidget *textEditorWidget,
|
||||
int position,
|
||||
const QString &fileName,
|
||||
@@ -126,7 +126,7 @@ public:
|
||||
const Internal::PchInfo::Ptr &pchInfo,
|
||||
const CPlusPlus::LanguageFeatures &features);
|
||||
|
||||
ClangCodeModel::Internal::IpcCommunicator::Ptr ipcCommunicator() const;
|
||||
ClangCodeModel::Internal::IpcCommunicator &ipcCommunicator() const;
|
||||
const ClangCodeModel::Internal::UnsavedFiles &unsavedFiles() const;
|
||||
bool objcEnabled() const;
|
||||
const CppTools::ProjectPart::HeaderPaths &headerPaths() const;
|
||||
@@ -136,7 +136,7 @@ public:
|
||||
void setHeaderPaths(const CppTools::ProjectPart::HeaderPaths &headerPaths); // For tests
|
||||
|
||||
private:
|
||||
ClangCodeModel::Internal::IpcCommunicator::Ptr m_ipcCommunicator;
|
||||
ClangCodeModel::Internal::IpcCommunicator &m_ipcCommunicator;
|
||||
ClangCodeModel::Internal::UnsavedFiles m_unsavedFiles;
|
||||
QStringList m_options;
|
||||
CppTools::ProjectPart::HeaderPaths m_headerPaths;
|
||||
|
||||
@@ -137,7 +137,7 @@ ClangEditorDocumentProcessor::~ClangEditorDocumentProcessor()
|
||||
projectFilePath = projectPart->projectFile; // OK, Project Part is still loaded
|
||||
|
||||
QTC_ASSERT(m_modelManagerSupport, return);
|
||||
m_modelManagerSupport->ipcCommunicator()->unregisterFilesForCodeCompletion(
|
||||
m_modelManagerSupport->ipcCommunicator().unregisterFilesForCodeCompletion(
|
||||
{ClangBackEnd::FileContainer(filePath(), projectFilePath)});
|
||||
}
|
||||
|
||||
|
||||
@@ -58,8 +58,7 @@ static CppTools::CppModelManager *cppModelManager()
|
||||
}
|
||||
|
||||
ModelManagerSupportClang::ModelManagerSupportClang()
|
||||
: m_ipcCommunicator(new IpcCommunicator)
|
||||
, m_completionAssistProvider(new ClangCompletionAssistProvider(m_ipcCommunicator))
|
||||
: m_completionAssistProvider(m_ipcCommunicator)
|
||||
{
|
||||
QTC_CHECK(!m_instance);
|
||||
m_instance = this;
|
||||
@@ -84,7 +83,7 @@ ModelManagerSupportClang::~ModelManagerSupportClang()
|
||||
|
||||
CppTools::CppCompletionAssistProvider *ModelManagerSupportClang::completionAssistProvider()
|
||||
{
|
||||
return m_completionAssistProvider.data();
|
||||
return &m_completionAssistProvider;
|
||||
}
|
||||
|
||||
CppTools::BaseEditorDocumentProcessor *ModelManagerSupportClang::editorDocumentProcessor(
|
||||
@@ -98,7 +97,7 @@ void ModelManagerSupportClang::onCurrentEditorChanged(Core::IEditor *newCurrent)
|
||||
// If we switch away from a cpp editor, update the backend about
|
||||
// the document's unsaved content.
|
||||
if (m_previousCppEditor && m_previousCppEditor->document()->isModified()) {
|
||||
m_ipcCommunicator->updateUnsavedFileFromCppEditorDocument(
|
||||
m_ipcCommunicator.updateUnsavedFileFromCppEditorDocument(
|
||||
m_previousCppEditor->document()->filePath().toString());
|
||||
}
|
||||
|
||||
@@ -138,20 +137,20 @@ void ModelManagerSupportClang::onCppDocumentReloadFinished(bool success)
|
||||
return;
|
||||
|
||||
Core::IDocument *document = qobject_cast<Core::IDocument *>(sender());
|
||||
m_ipcCommunicator->updateUnsavedFileIfNotCurrentDocument(document);
|
||||
m_ipcCommunicator.updateUnsavedFileIfNotCurrentDocument(document);
|
||||
}
|
||||
|
||||
void ModelManagerSupportClang::onCppDocumentContentsChanged()
|
||||
{
|
||||
Core::IDocument *document = qobject_cast<Core::IDocument *>(sender());
|
||||
m_ipcCommunicator->updateUnsavedFileIfNotCurrentDocument(document);
|
||||
m_ipcCommunicator.updateUnsavedFileIfNotCurrentDocument(document);
|
||||
}
|
||||
|
||||
void ModelManagerSupportClang::onAbstractEditorSupportContentsUpdated(const QString &filePath,
|
||||
const QByteArray &content)
|
||||
{
|
||||
QTC_ASSERT(!filePath.isEmpty(), return);
|
||||
m_ipcCommunicator->updateUnsavedFile(filePath, content);
|
||||
m_ipcCommunicator.updateUnsavedFile(filePath, content);
|
||||
}
|
||||
|
||||
void ModelManagerSupportClang::onAbstractEditorSupportRemoved(const QString &filePath)
|
||||
@@ -159,7 +158,7 @@ void ModelManagerSupportClang::onAbstractEditorSupportRemoved(const QString &fil
|
||||
QTC_ASSERT(!filePath.isEmpty(), return);
|
||||
if (!cppModelManager()->cppEditorDocument(filePath)) {
|
||||
const QString projectFilePath = Utils::projectFilePathForFile(filePath);
|
||||
m_ipcCommunicator->unregisterFilesForCodeCompletion(
|
||||
m_ipcCommunicator.unregisterFilesForCodeCompletion(
|
||||
{ClangBackEnd::FileContainer(filePath, projectFilePath)});
|
||||
}
|
||||
}
|
||||
@@ -169,12 +168,12 @@ void ModelManagerSupportClang::onProjectPartsUpdated(ProjectExplorer::Project *p
|
||||
QTC_ASSERT(project, return);
|
||||
const CppTools::ProjectInfo projectInfo = cppModelManager()->projectInfo(project);
|
||||
QTC_ASSERT(projectInfo.isValid(), return);
|
||||
m_ipcCommunicator->registerProjectsParts(projectInfo.projectParts());
|
||||
m_ipcCommunicator.registerProjectsParts(projectInfo.projectParts());
|
||||
}
|
||||
|
||||
void ModelManagerSupportClang::onProjectPartsRemoved(const QStringList &projectFiles)
|
||||
{
|
||||
m_ipcCommunicator->unregisterProjectPartsForCodeCompletion(projectFiles);
|
||||
m_ipcCommunicator.unregisterProjectPartsForCodeCompletion(projectFiles);
|
||||
}
|
||||
|
||||
ModelManagerSupportClang *ModelManagerSupportClang::instance()
|
||||
@@ -182,7 +181,7 @@ ModelManagerSupportClang *ModelManagerSupportClang::instance()
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
IpcCommunicator::Ptr ModelManagerSupportClang::ipcCommunicator()
|
||||
IpcCommunicator &ModelManagerSupportClang::ipcCommunicator()
|
||||
{
|
||||
return m_ipcCommunicator;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public:
|
||||
CppTools::BaseEditorDocumentProcessor *editorDocumentProcessor(
|
||||
TextEditor::TextDocument *baseTextDocument) override;
|
||||
|
||||
IpcCommunicator::Ptr ipcCommunicator();
|
||||
IpcCommunicator &ipcCommunicator();
|
||||
|
||||
public: // for tests
|
||||
static ModelManagerSupportClang *instance();
|
||||
@@ -75,8 +75,8 @@ private:
|
||||
void onProjectPartsUpdated(ProjectExplorer::Project *project);
|
||||
void onProjectPartsRemoved(const QStringList &projectFiles);
|
||||
|
||||
IpcCommunicator::Ptr m_ipcCommunicator;
|
||||
QScopedPointer<ClangCompletionAssistProvider> m_completionAssistProvider;
|
||||
IpcCommunicator m_ipcCommunicator;
|
||||
ClangCompletionAssistProvider m_completionAssistProvider;
|
||||
QPointer<Core::IEditor> m_previousCppEditor;
|
||||
};
|
||||
|
||||
|
||||
@@ -241,13 +241,12 @@ class ChangeIpcSender
|
||||
public:
|
||||
ChangeIpcSender(IpcSenderInterface *ipcSender)
|
||||
{
|
||||
m_previousSender = ModelManagerSupportClang::instance()->ipcCommunicator()
|
||||
->setIpcSender(ipcSender);
|
||||
m_previousSender = ModelManagerSupportClang::instance()->ipcCommunicator().setIpcSender(ipcSender);
|
||||
}
|
||||
|
||||
~ChangeIpcSender()
|
||||
{
|
||||
ModelManagerSupportClang::instance()->ipcCommunicator()->setIpcSender(m_previousSender);
|
||||
ModelManagerSupportClang::instance()->ipcCommunicator().setIpcSender(m_previousSender);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -941,9 +940,9 @@ void ClangCodeCompletionTest::testUpdateBackendAfterRestart()
|
||||
spy.senderLog.clear();
|
||||
|
||||
// Kill backend process...
|
||||
IpcCommunicator::Ptr ipcCommunicator = ModelManagerSupportClang::instance()->ipcCommunicator();
|
||||
ipcCommunicator->killBackendProcess();
|
||||
QSignalSpy waitForReinitializedBackend(ipcCommunicator.data(),
|
||||
IpcCommunicator &ipcCommunicator = ModelManagerSupportClang::instance()->ipcCommunicator();
|
||||
ipcCommunicator.killBackendProcess();
|
||||
QSignalSpy waitForReinitializedBackend(&ipcCommunicator,
|
||||
SIGNAL(backendReinitialized()));
|
||||
QVERIFY(waitForReinitializedBackend.wait());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user