Commit 831fb618 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh
Browse files

CppTools: Remove assertions for CppModelManager::instance()



It cannot return null.

Change-Id: I3ac5f33e7e02554edc8df067c7b85518e58c1fc2
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent a22dc36a
......@@ -402,14 +402,10 @@ QList<Node *> AutotoolsProject::nodes(FolderNode *parent) const
void AutotoolsProject::updateCppCodeModel()
{
CppTools::CppModelManager *modelManager =
CppTools::CppModelManager::instance();
if (!modelManager)
return;
CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance();
m_codeModelFuture.cancel();
CppTools::ProjectInfo pInfo = CppTools::ProjectInfo(this);
CppTools::ProjectInfo pInfo(this);
CppTools::ProjectPartBuilder ppBuilder(pInfo);
const QStringList cflags = m_makefileParserThread->cflags();
......
......@@ -555,7 +555,6 @@ ClangCompletionAssistInterface::ClangCompletionAssistInterface(ClangCompleter::P
Q_ASSERT(!clangWrapper.isNull());
CppModelManager *mmi = CppModelManager::instance();
Q_ASSERT(mmi);
m_unsavedFiles = Utils::createUnsavedFiles(mmi->workingCopy());
}
......
......@@ -270,8 +270,7 @@ void Manager::initialize()
&d->parser, SLOT(setFlatMode(bool)), Qt::QueuedConnection);
// connect to the cpp model manager for signals about document updates
CppTools::CppModelManager *codeModelManager
= CppTools::CppModelManager::instance();
CppTools::CppModelManager *codeModelManager = CppTools::CppModelManager::instance();
// when code manager signals that document is updated - handle it by ourselves
connect(codeModelManager, SIGNAL(documentUpdated(CPlusPlus::Document::Ptr)),
......
......@@ -667,9 +667,7 @@ void Parser::resetData(const CPlusPlus::Snapshot &snapshot)
void Parser::resetDataToCurrentState()
{
// get latest data
CppTools::CppModelManager *codeModel = CppTools::CppModelManager::instance();
if (codeModel)
resetData(codeModel->snapshot());
resetData(CppTools::CppModelManager::instance()->snapshot());
}
/*!
......
......@@ -312,32 +312,29 @@ bool CMakeProject::parseCMakeLists()
return true;
}
CppTools::CppModelManager *modelmanager =
CppTools::CppModelManager::instance();
if (modelmanager) {
CppTools::ProjectInfo pinfo = CppTools::ProjectInfo(this);
CppTools::ProjectPartBuilder ppBuilder(pinfo);
foreach (const CMakeBuildTarget &cbt, m_buildTargets) {
// This explicitly adds -I. to the include paths
QStringList includePaths = cbt.includeFiles;
includePaths += projectDirectory().toString();
ppBuilder.setIncludePaths(includePaths);
ppBuilder.setCFlags(getCXXFlagsFor(cbt));
ppBuilder.setCxxFlags(getCXXFlagsFor(cbt));
ppBuilder.setDefines(cbt.defines);
ppBuilder.setDisplayName(cbt.title);
const QList<Core::Id> languages = ppBuilder.createProjectPartsForFiles(cbt.files);
foreach (Core::Id language, languages)
setProjectLanguage(language, true);
}
m_codeModelFuture.cancel();
pinfo.finish();
m_codeModelFuture = modelmanager->updateProjectInfo(pinfo);
CppTools::CppModelManager *modelmanager = CppTools::CppModelManager::instance();
CppTools::ProjectInfo pinfo(this);
CppTools::ProjectPartBuilder ppBuilder(pinfo);
foreach (const CMakeBuildTarget &cbt, m_buildTargets) {
// This explicitly adds -I. to the include paths
QStringList includePaths = cbt.includeFiles;
includePaths += projectDirectory().toString();
ppBuilder.setIncludePaths(includePaths);
ppBuilder.setCFlags(getCXXFlagsFor(cbt));
ppBuilder.setCxxFlags(getCXXFlagsFor(cbt));
ppBuilder.setDefines(cbt.defines);
ppBuilder.setDisplayName(cbt.title);
const QList<Core::Id> languages = ppBuilder.createProjectPartsForFiles(cbt.files);
foreach (Core::Id language, languages)
setProjectLanguage(language, true);
}
m_codeModelFuture.cancel();
pinfo.finish();
m_codeModelFuture = modelmanager->updateProjectInfo(pinfo);
emit displayNameChanged();
emit buildTargetsChanged();
emit fileListChanged();
......
......@@ -187,9 +187,6 @@ QWidget *CppEditorOutline::widget() const
void CppEditorOutline::updateNow()
{
CppTools::CppModelManager *cmmi = CppTools::CppModelManager::instance();
if (!cmmi)
return;
const CPlusPlus::Snapshot snapshot = cmmi->snapshot();
const QString filePath = m_editorWidget->textDocument()->filePath().toString();
CPlusPlus::Document::Ptr document = snapshot.document(filePath);
......
......@@ -358,7 +358,6 @@ VerifyCleanCppModelManager::~VerifyCleanCppModelManager() {
bool VerifyCleanCppModelManager::isClean()
{
CppModelManager *mm = CppModelManager::instance();
RETURN_FALSE_IF_NOT(mm);
RETURN_FALSE_IF_NOT(mm->projectInfos().isEmpty());
RETURN_FALSE_IF_NOT(mm->headerPaths().isEmpty());
RETURN_FALSE_IF_NOT(mm->definedMacros().isEmpty());
......
......@@ -58,8 +58,6 @@ ModelManagerTestHelper::ModelManagerTestHelper(QObject *parent) :
{
CppModelManager *mm = CppModelManager::instance();
assert(mm);
connect(this, &ModelManagerTestHelper::aboutToRemoveProject,
mm, &CppModelManager::onAboutToRemoveProject);
connect(this, &ModelManagerTestHelper::projectAdded,
......@@ -82,8 +80,6 @@ ModelManagerTestHelper::~ModelManagerTestHelper()
void ModelManagerTestHelper::cleanup()
{
CppModelManager *mm = CppModelManager::instance();
assert(mm);
QList<ProjectInfo> pies = mm->projectInfos();
foreach (const ProjectInfo &pie, pies)
emit aboutToRemoveProject(pie.project().data());
......
......@@ -252,15 +252,14 @@ static Function *findDeclaration(const Class *cl, const QString &functionName)
// TODO: remove me, this is taken from cppeditor.cpp. Find some common place for this function
static Document::Ptr findDefinition(Function *functionDeclaration, int *line)
{
if (CppTools::CppModelManager *cppModelManager = CppTools::CppModelManager::instance()) {
const Snapshot snapshot = cppModelManager->snapshot();
CppTools::SymbolFinder symbolFinder;
if (Function *fun = symbolFinder.findMatchingDefinition(functionDeclaration, snapshot)) {
if (line)
*line = fun->line();
return snapshot.document(QString::fromUtf8(fun->fileName(), fun->fileNameLength()));
}
CppTools::CppModelManager *cppModelManager = CppTools::CppModelManager::instance();
const Snapshot snapshot = cppModelManager->snapshot();
CppTools::SymbolFinder symbolFinder;
if (Function *fun = symbolFinder.findMatchingDefinition(functionDeclaration, snapshot)) {
if (line)
*line = fun->line();
return snapshot.document(QString::fromUtf8(fun->fileName(), fun->fileNameLength()));
}
return Document::Ptr();
......
......@@ -344,15 +344,11 @@ QStringList GenericProject::processEntries(const QStringList &paths,
void GenericProject::refreshCppCodeModel()
{
CppTools::CppModelManager *modelManager =
CppTools::CppModelManager::instance();
if (!modelManager)
return;
CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance();
m_codeModelFuture.cancel();
CppTools::ProjectInfo pInfo = CppTools::ProjectInfo(this);
CppTools::ProjectInfo pInfo(this);
CppTools::ProjectPartBuilder ppBuilder(pInfo);
ppBuilder.setIncludePaths(projectIncludePaths());
ppBuilder.setConfigFileName(configFileName());
......
......@@ -689,10 +689,7 @@ void QbsProject::updateCppCodeModel()
QtSupport::QtKitInformation::qtVersion(activeTarget()->kit());
CppTools::CppModelManager *modelmanager = CppTools::CppModelManager::instance();
if (!modelmanager)
return;
CppTools::ProjectInfo pinfo = CppTools::ProjectInfo(this);
CppTools::ProjectInfo pinfo(this);
CppTools::ProjectPartBuilder ppBuilder(pinfo);
if (qtVersion) {
......
......@@ -470,24 +470,18 @@ void QmakeProject::updateCppCodeModel()
typedef CppTools::ProjectFile ProjectFile;
Kit *k = 0;
QtSupport::BaseQtVersion *qtVersion = 0;
if (Target *target = activeTarget())
k = target->kit();
else
k = KitManager::defaultKit();
qtVersion = QtSupport::QtKitInformation::qtVersion(k);
CppTools::CppModelManager *modelmanager =
CppTools::CppModelManager::instance();
if (!modelmanager)
return;
CppTools::CppModelManager *modelmanager = CppTools::CppModelManager::instance();
FindQmakeProFiles findQmakeProFiles;
QList<QmakeProFileNode *> proFiles = findQmakeProFiles(rootProjectNode());
CppTools::ProjectInfo pinfo = CppTools::ProjectInfo(this);
CppTools::ProjectInfo pinfo(this);
QtSupport::BaseQtVersion *qtVersion = QtSupport::QtKitInformation::qtVersion(k);
ProjectPart::QtVersion qtVersionForPart = ProjectPart::NoQt;
if (qtVersion) {
if (qtVersion->qtVersion() < QtSupport::QtVersionNumber(5,0,0))
......
......@@ -214,14 +214,11 @@ ModelManager::~ModelManager()
void ModelManager::delayedInitialization()
{
CppTools::CppModelManager *cppModelManager =
CppTools::CppModelManager::instance();
if (cppModelManager) {
// It's important to have a direct connection here so we can prevent
// the source and AST of the cpp document being cleaned away.
connect(cppModelManager, SIGNAL(documentUpdated(CPlusPlus::Document::Ptr)),
this, SLOT(maybeQueueCppQmlTypeUpdate(CPlusPlus::Document::Ptr)), Qt::DirectConnection);
}
CppTools::CppModelManager *cppModelManager = CppTools::CppModelManager::instance();
// It's important to have a direct connection here so we can prevent
// the source and AST of the cpp document being cleaned away.
connect(cppModelManager, SIGNAL(documentUpdated(CPlusPlus::Document::Ptr)),
this, SLOT(maybeQueueCppQmlTypeUpdate(CPlusPlus::Document::Ptr)), Qt::DirectConnection);
connect(ProjectExplorer::SessionManager::instance(), &ProjectExplorer::SessionManager::projectRemoved,
this, &ModelManager::removeProjectInfo);
......
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