Commit 4d3d0e02 authored by Nikolai Kosjar's avatar Nikolai Kosjar

CppTools: Rename EditorDocumentHandle to CppEditorDocumentHandle

...and related functions. For clarity in client code.

Change-Id: Icad6fc7b1eee2ce46a2eba8435359837a23409c8
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@theqtcompany.com>
parent 845cb2e4
......@@ -1362,10 +1362,10 @@ void CppCodeModelInspectorDialog::refresh()
dumper.dumpSnapshot(globalSnapshot, globalSnapshotTitle, /*isGlobalSnapshot=*/ true);
TextEditor::BaseTextEditor *editor = currentEditor();
EditorDocumentHandle *editorDocument = 0;
CppEditorDocumentHandle *cppEditorDocument = 0;
if (editor) {
const QString editorFilePath = editor->document()->filePath().toString();
editorDocument = cmmi->editorDocument(editorFilePath);
cppEditorDocument = cmmi->cppEditorDocument(editorFilePath);
if (auto *documentProcessor = BaseEditorDocumentProcessor::get(editorFilePath)) {
const CPlusPlus::Snapshot editorSnapshot = documentProcessor->snapshot();
m_snapshotInfos->append(SnapshotInfo(editorSnapshot, SnapshotInfo::EditorSnapshot));
......@@ -1416,8 +1416,8 @@ void CppCodeModelInspectorDialog::refresh()
onSnapshotSelected(snapshotIndex);
// Project Parts
const ProjectPart::Ptr editorsProjectPart = editorDocument
? editorDocument->processor()->parser()->projectPart()
const ProjectPart::Ptr editorsProjectPart = cppEditorDocument
? cppEditorDocument->processor()->parser()->projectPart()
: ProjectPart::Ptr();
const QList<ProjectInfo> projectInfos = cmmi->projectInfos();
......
......@@ -63,17 +63,17 @@ namespace Internal {
enum { processDocumentIntervalInMs = 150 };
class CppEditorDocumentHandle : public CppTools::EditorDocumentHandle
class CppEditorDocumentHandle : public CppTools::CppEditorDocumentHandle
{
public:
CppEditorDocumentHandle(CppEditor::Internal::CppEditorDocument *cppEditorDocument)
: m_cppEditorDocument(cppEditorDocument)
, m_registrationFilePath(cppEditorDocument->filePath().toString())
{
mm()->registerEditorDocument(this);
mm()->registerCppEditorDocument(this);
}
~CppEditorDocumentHandle() { mm()->unregisterEditorDocument(m_registrationFilePath); }
~CppEditorDocumentHandle() { mm()->unregisterCppEditorDocument(m_registrationFilePath); }
QString filePath() const { return m_cppEditorDocument->filePath().toString(); }
QByteArray contents() const { return m_cppEditorDocument->contentsText(); }
......
......@@ -117,7 +117,7 @@ private:
CppTools::CppCompletionAssistProvider *m_completionAssistProvider;
// (Un)Registration in CppModelManager
QScopedPointer<CppTools::EditorDocumentHandle> m_editorDocumentHandle;
QScopedPointer<CppTools::CppEditorDocumentHandle> m_editorDocumentHandle;
};
} // namespace Internal
......
......@@ -107,8 +107,8 @@ void BaseEditorDocumentParser::setEditorDefines(const QByteArray &editorDefines)
BaseEditorDocumentParser *BaseEditorDocumentParser::get(const QString &filePath)
{
CppModelManager *cmmi = CppModelManager::instance();
if (EditorDocumentHandle *editorDocument = cmmi->editorDocument(filePath)) {
if (BaseEditorDocumentProcessor *processor = editorDocument->processor())
if (CppEditorDocumentHandle *cppEditorDocument = cmmi->cppEditorDocument(filePath)) {
if (BaseEditorDocumentProcessor *processor = cppEditorDocument->processor())
return processor->parser();
}
return 0;
......
......@@ -66,8 +66,8 @@ TextEditor::TextDocument *BaseEditorDocumentProcessor::baseTextDocument() const
BaseEditorDocumentProcessor *BaseEditorDocumentProcessor::get(const QString &filePath)
{
CppModelManager *cmmi = CppModelManager::instance();
if (EditorDocumentHandle *editorDocument = cmmi->editorDocument(filePath))
return editorDocument->processor();
if (CppEditorDocumentHandle *cppEditorDocument = cmmi->cppEditorDocument(filePath))
return cppEditorDocument->processor();
return 0;
}
......
......@@ -139,8 +139,8 @@ public:
QByteArray m_definedMacros;
// Editor integration
mutable QMutex m_cppEditorsMutex;
QMap<QString, EditorDocumentHandle *> m_cppEditors;
mutable QMutex m_cppEditorDocumentsMutex;
QMap<QString, CppEditorDocumentHandle *> m_cppEditorDocuments;
QSet<AbstractEditorSupport *> m_extraEditorSupports;
// Completion & highlighting
......@@ -462,27 +462,27 @@ void CppModelManager::removeExtraEditorSupport(AbstractEditorSupport *editorSupp
d->m_extraEditorSupports.remove(editorSupport);
}
EditorDocumentHandle *CppModelManager::editorDocument(const QString &filePath) const
CppEditorDocumentHandle *CppModelManager::cppEditorDocument(const QString &filePath) const
{
if (filePath.isEmpty())
return 0;
QMutexLocker locker(&d->m_cppEditorsMutex);
return d->m_cppEditors.value(filePath, 0);
QMutexLocker locker(&d->m_cppEditorDocumentsMutex);
return d->m_cppEditorDocuments.value(filePath, 0);
}
void CppModelManager::registerEditorDocument(EditorDocumentHandle *editorDocument)
void CppModelManager::registerCppEditorDocument(CppEditorDocumentHandle *editorDocument)
{
QTC_ASSERT(editorDocument, return);
const QString filePath = editorDocument->filePath();
QTC_ASSERT(!filePath.isEmpty(), return);
QMutexLocker locker(&d->m_cppEditorsMutex);
QTC_ASSERT(d->m_cppEditors.value(filePath, 0) == 0, return);
d->m_cppEditors.insert(filePath, editorDocument);
QMutexLocker locker(&d->m_cppEditorDocumentsMutex);
QTC_ASSERT(d->m_cppEditorDocuments.value(filePath, 0) == 0, return);
d->m_cppEditorDocuments.insert(filePath, editorDocument);
}
void CppModelManager::unregisterEditorDocument(const QString &filePath)
void CppModelManager::unregisterCppEditorDocument(const QString &filePath)
{
QTC_ASSERT(!filePath.isEmpty(), return);
......@@ -490,10 +490,10 @@ void CppModelManager::unregisterEditorDocument(const QString &filePath)
int openCppDocuments = 0;
{
QMutexLocker locker(&d->m_cppEditorsMutex);
QTC_ASSERT(d->m_cppEditors.value(filePath, 0), return);
QTC_CHECK(d->m_cppEditors.remove(filePath) == 1);
openCppDocuments = d->m_cppEditors.size();
QMutexLocker locker(&d->m_cppEditorDocumentsMutex);
QTC_ASSERT(d->m_cppEditorDocuments.value(filePath, 0), return);
QTC_CHECK(d->m_cppEditorDocuments.remove(filePath) == 1);
openCppDocuments = d->m_cppEditorDocuments.size();
}
++closedCppDocuments;
......@@ -542,8 +542,11 @@ WorkingCopy CppModelManager::buildWorkingCopyList()
{
WorkingCopy workingCopy;
foreach (const EditorDocumentHandle *cppEditor, cppEditors())
workingCopy.insert(cppEditor->filePath(), cppEditor->contents(), cppEditor->revision());
foreach (const CppEditorDocumentHandle *cppEditorDocument, cppEditorDocuments()) {
workingCopy.insert(cppEditorDocument->filePath(),
cppEditorDocument->contents(),
cppEditorDocument->revision());
}
QSetIterator<AbstractEditorSupport *> it(d->m_extraEditorSupports);
while (it.hasNext()) {
......@@ -608,10 +611,10 @@ void CppModelManager::removeProjectInfoFilesAndIncludesFromSnapshot(const Projec
}
}
QList<EditorDocumentHandle *> CppModelManager::cppEditors() const
QList<CppEditorDocumentHandle *> CppModelManager::cppEditorDocuments() const
{
QMutexLocker locker(&d->m_cppEditorsMutex);
return d->m_cppEditors.values();
QMutexLocker locker(&d->m_cppEditorDocumentsMutex);
return d->m_cppEditorDocuments.values();
}
/// \brief Remove all given files from the snapshot.
......@@ -699,9 +702,10 @@ void CppModelManager::updateCppEditorDocuments() const
QSet<Core::IDocument *> visibleCppEditorDocuments;
foreach (Core::IEditor *editor, Core::EditorManager::visibleEditors()) {
if (Core::IDocument *document = editor->document()) {
if (EditorDocumentHandle *cppEditorDocument = editorDocument(document->filePath().toString())) {
const QString filePath = document->filePath().toString();
if (CppEditorDocumentHandle *theCppEditorDocument = cppEditorDocument(filePath)) {
visibleCppEditorDocuments.insert(document);
cppEditorDocument->processor()->run();
theCppEditorDocument->processor()->run();
}
}
}
......@@ -711,8 +715,9 @@ void CppModelManager::updateCppEditorDocuments() const
= Core::DocumentModel::openedDocuments().toSet();
invisibleCppEditorDocuments.subtract(visibleCppEditorDocuments);
foreach (Core::IDocument *document, invisibleCppEditorDocuments) {
if (EditorDocumentHandle *cppEditorDocument = editorDocument(document->filePath().toString()))
cppEditorDocument->setNeedsRefresh(true);
const QString filePath = document->filePath().toString();
if (CppEditorDocumentHandle *theCppEditorDocument = cppEditorDocument(filePath))
theCppEditorDocument->setNeedsRefresh(true);
}
}
......@@ -887,11 +892,11 @@ void CppModelManager::onCurrentEditorChanged(Core::IEditor *editor)
if (!editor || !editor->document())
return;
if (EditorDocumentHandle *cppEditorDocument =
editorDocument(editor->document()->filePath().toString())) {
if (cppEditorDocument->needsRefresh()) {
cppEditorDocument->setNeedsRefresh(false);
cppEditorDocument->processor()->run();
const QString filePath = editor->document()->filePath().toString();
if (CppEditorDocumentHandle *theCppEditorDocument = cppEditorDocument(filePath)) {
if (theCppEditorDocument->needsRefresh()) {
theCppEditorDocument->setNeedsRefresh(false);
theCppEditorDocument->processor()->run();
}
}
}
......@@ -955,8 +960,8 @@ void CppModelManager::GC()
// Collect files of opened editors and editor supports (e.g. ui code model)
QStringList filesInEditorSupports;
foreach (const EditorDocumentHandle *cppEditor, cppEditors())
filesInEditorSupports << cppEditor->filePath();
foreach (const CppEditorDocumentHandle *editorDocument, cppEditorDocuments())
filesInEditorSupports << editorDocument->filePath();
QSetIterator<AbstractEditorSupport *> jt(d->m_extraEditorSupports);
while (jt.hasNext()) {
......
......@@ -55,7 +55,7 @@ namespace CppTools {
class AbstractEditorSupport;
class BaseEditorDocumentProcessor;
class CppCompletionAssistProvider;
class EditorDocumentHandle;
class CppEditorDocumentHandle;
class CppIndexingSupport;
class ModelManagerSupport;
class WorkingCopy;
......@@ -117,9 +117,9 @@ public:
void addExtraEditorSupport(AbstractEditorSupport *editorSupport);
void removeExtraEditorSupport(AbstractEditorSupport *editorSupport);
EditorDocumentHandle *editorDocument(const QString &filePath) const;
void registerEditorDocument(EditorDocumentHandle *editorDocument);
void unregisterEditorDocument(const QString &filePath);
CppEditorDocumentHandle *cppEditorDocument(const QString &filePath) const;
void registerCppEditorDocument(CppEditorDocumentHandle *cppEditorDocument);
void unregisterCppEditorDocument(const QString &filePath);
QList<int> references(CPlusPlus::Symbol *symbol, const CPlusPlus::LookupContext &context);
......@@ -198,7 +198,7 @@ private:
void removeFilesFromSnapshot(const QSet<QString> &removedFiles);
void removeProjectInfoFilesAndIncludesFromSnapshot(const ProjectInfo &projectInfo);
QList<EditorDocumentHandle *> cppEditors() const;
QList<CppEditorDocumentHandle *> cppEditorDocuments() const;
WorkingCopy buildWorkingCopyList();
......
......@@ -1014,7 +1014,7 @@ void CppToolsPlugin::test_modelmanager_updateEditorsAfterProjectUpdate()
EditorCloser closerA(editorA);
QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1);
EditorDocumentHandle *editorDocumentA = mm->editorDocument(fileA);
CppEditorDocumentHandle *editorDocumentA = mm->cppEditorDocument(fileA);
QVERIFY(editorDocumentA);
ProjectPart::Ptr documentAProjectPart = editorDocumentA->processor()->parser()->projectPart();
QVERIFY(!documentAProjectPart->project);
......@@ -1025,7 +1025,7 @@ void CppToolsPlugin::test_modelmanager_updateEditorsAfterProjectUpdate()
EditorCloser closerB(editorB);
QCOMPARE(Core::DocumentModel::openedDocuments().size(), 2);
EditorDocumentHandle *editorDocumentB = mm->editorDocument(fileB);
CppEditorDocumentHandle *editorDocumentB = mm->cppEditorDocument(fileB);
QVERIFY(editorDocumentB);
ProjectPart::Ptr documentBProjectPart = editorDocumentB->processor()->parser()->projectPart();
QVERIFY(!documentBProjectPart->project);
......
......@@ -39,21 +39,21 @@ namespace CppTools {
C++ editor document.
*/
EditorDocumentHandle::EditorDocumentHandle()
CppEditorDocumentHandle::CppEditorDocumentHandle()
: m_needsRefresh(false)
{
}
EditorDocumentHandle::~EditorDocumentHandle()
CppEditorDocumentHandle::~CppEditorDocumentHandle()
{
}
bool EditorDocumentHandle::needsRefresh() const
bool CppEditorDocumentHandle::needsRefresh() const
{
return m_needsRefresh;
}
void EditorDocumentHandle::setNeedsRefresh(bool needsRefresh)
void CppEditorDocumentHandle::setNeedsRefresh(bool needsRefresh)
{
m_needsRefresh = needsRefresh;
}
......
......@@ -36,11 +36,11 @@
namespace CppTools {
class CPPTOOLS_EXPORT EditorDocumentHandle
class CPPTOOLS_EXPORT CppEditorDocumentHandle
{
public:
EditorDocumentHandle();
virtual ~EditorDocumentHandle();
CppEditorDocumentHandle();
virtual ~CppEditorDocumentHandle();
bool needsRefresh() const;
void setNeedsRefresh(bool needsRefresh);
......
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