2014-07-30 17:37:17 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2014-07-30 17:37:17 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2014-07-30 17:37:17 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2014-07-30 17:37:17 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "baseeditordocumentparser.h"
|
2015-03-05 08:22:48 +01:00
|
|
|
#include "baseeditordocumentprocessor.h"
|
2014-07-30 17:37:17 +02:00
|
|
|
|
2015-12-15 11:59:48 +01:00
|
|
|
#include "cppmodelmanager.h"
|
2016-12-16 13:10:43 +01:00
|
|
|
#include "cppprojectpartchooser.h"
|
2014-08-19 15:59:29 +02:00
|
|
|
#include "editordocumenthandle.h"
|
|
|
|
|
|
2014-07-30 17:37:17 +02:00
|
|
|
namespace CppTools {
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\class CppTools::BaseEditorDocumentParser
|
|
|
|
|
|
|
|
|
|
\brief The BaseEditorDocumentParser class parses a source text as
|
|
|
|
|
precisely as possible.
|
|
|
|
|
|
|
|
|
|
It's meant to be used in the C++ editor to get precise results by using
|
|
|
|
|
the "best" project part for a file.
|
|
|
|
|
|
2015-07-10 12:34:40 +02:00
|
|
|
Derived classes are expected to implement updateHelper() this way:
|
2015-07-07 15:02:14 +02:00
|
|
|
|
|
|
|
|
\list
|
|
|
|
|
\li Get a copy of the configuration and the last state.
|
|
|
|
|
\li Work on the data and do whatever is necessary. At least, update
|
|
|
|
|
the project part with the help of determineProjectPart().
|
2015-07-10 12:34:40 +02:00
|
|
|
\li Ensure the new state is set before updateHelper() returns.
|
2015-07-07 15:02:14 +02:00
|
|
|
\endlist
|
2014-07-30 17:37:17 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
BaseEditorDocumentParser::BaseEditorDocumentParser(const QString &filePath)
|
2015-07-07 15:02:14 +02:00
|
|
|
: m_filePath(filePath)
|
2014-07-30 17:37:17 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BaseEditorDocumentParser::~BaseEditorDocumentParser()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString BaseEditorDocumentParser::filePath() const
|
|
|
|
|
{
|
|
|
|
|
return m_filePath;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-07 15:02:14 +02:00
|
|
|
BaseEditorDocumentParser::Configuration BaseEditorDocumentParser::configuration() const
|
2014-07-30 17:37:17 +02:00
|
|
|
{
|
2015-07-07 15:02:14 +02:00
|
|
|
QMutexLocker locker(&m_stateAndConfigurationMutex);
|
|
|
|
|
return m_configuration;
|
2014-07-30 17:37:17 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-07 15:02:14 +02:00
|
|
|
void BaseEditorDocumentParser::setConfiguration(const Configuration &configuration)
|
2014-07-30 17:37:17 +02:00
|
|
|
{
|
2015-07-07 15:02:14 +02:00
|
|
|
QMutexLocker locker(&m_stateAndConfigurationMutex);
|
|
|
|
|
m_configuration = configuration;
|
2014-07-30 17:37:17 +02:00
|
|
|
}
|
|
|
|
|
|
2016-12-16 13:12:04 +01:00
|
|
|
void BaseEditorDocumentParser::update(const WorkingCopy &workingCopy,
|
|
|
|
|
const ProjectExplorer::Project *activeProject)
|
2016-07-27 14:48:42 +02:00
|
|
|
{
|
|
|
|
|
QFutureInterface<void> dummy;
|
2016-12-16 13:12:04 +01:00
|
|
|
update(dummy, workingCopy, activeProject);
|
2016-07-27 14:48:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BaseEditorDocumentParser::update(const QFutureInterface<void> &future,
|
2016-12-16 13:12:04 +01:00
|
|
|
const WorkingCopy &workingCopy,
|
|
|
|
|
const ProjectExplorer::Project *activeProject)
|
2015-07-10 12:34:40 +02:00
|
|
|
{
|
|
|
|
|
QMutexLocker locker(&m_updateIsRunning);
|
2016-12-16 13:12:04 +01:00
|
|
|
updateHelper(future, workingCopy, activeProject);
|
2015-07-10 12:34:40 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-07 15:02:14 +02:00
|
|
|
BaseEditorDocumentParser::State BaseEditorDocumentParser::state() const
|
2014-07-30 17:37:17 +02:00
|
|
|
{
|
2015-07-07 15:02:14 +02:00
|
|
|
QMutexLocker locker(&m_stateAndConfigurationMutex);
|
|
|
|
|
return m_state;
|
2014-07-30 17:37:17 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-07 15:02:14 +02:00
|
|
|
void BaseEditorDocumentParser::setState(const State &state)
|
2014-07-30 17:37:17 +02:00
|
|
|
{
|
2015-07-07 15:02:14 +02:00
|
|
|
QMutexLocker locker(&m_stateAndConfigurationMutex);
|
|
|
|
|
m_state = state;
|
2014-07-30 17:37:17 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-07 15:02:14 +02:00
|
|
|
ProjectPart::Ptr BaseEditorDocumentParser::projectPart() const
|
2014-07-30 17:37:17 +02:00
|
|
|
{
|
2015-07-07 15:02:14 +02:00
|
|
|
return state().projectPart;
|
2014-07-30 17:37:17 +02:00
|
|
|
}
|
|
|
|
|
|
2015-09-01 17:34:07 +02:00
|
|
|
BaseEditorDocumentParser::Ptr BaseEditorDocumentParser::get(const QString &filePath)
|
2014-08-19 15:59:29 +02:00
|
|
|
{
|
2014-09-15 00:12:27 +02:00
|
|
|
CppModelManager *cmmi = CppModelManager::instance();
|
2014-11-24 11:19:41 +01:00
|
|
|
if (CppEditorDocumentHandle *cppEditorDocument = cmmi->cppEditorDocument(filePath)) {
|
|
|
|
|
if (BaseEditorDocumentProcessor *processor = cppEditorDocument->processor())
|
2014-08-19 15:59:29 +02:00
|
|
|
return processor->parser();
|
|
|
|
|
}
|
2015-09-01 17:34:07 +02:00
|
|
|
return BaseEditorDocumentParser::Ptr();
|
2014-08-19 15:59:29 +02:00
|
|
|
}
|
|
|
|
|
|
2016-12-16 13:12:04 +01:00
|
|
|
ProjectPart::Ptr BaseEditorDocumentParser::determineProjectPart(
|
|
|
|
|
const QString &filePath,
|
|
|
|
|
const Configuration &config,
|
|
|
|
|
const State &state,
|
|
|
|
|
const ProjectExplorer::Project *activeProject)
|
2014-07-30 17:37:17 +02:00
|
|
|
{
|
2016-12-16 13:10:43 +01:00
|
|
|
Internal::ProjectPartChooser chooser;
|
|
|
|
|
chooser.setFallbackProjectPart([](){
|
|
|
|
|
return CppModelManager::instance()->fallbackProjectPart();
|
|
|
|
|
});
|
|
|
|
|
chooser.setProjectPartsForFile([](const QString &filePath) {
|
|
|
|
|
return CppModelManager::instance()->projectPart(filePath);
|
|
|
|
|
});
|
|
|
|
|
chooser.setProjectPartsFromDependenciesForFile([&](const QString &filePath) {
|
|
|
|
|
const auto fileName = Utils::FileName::fromString(filePath);
|
|
|
|
|
return CppModelManager::instance()->projectPartFromDependencies(fileName);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return chooser.choose(filePath,
|
|
|
|
|
state.projectPart,
|
|
|
|
|
config.manuallySetProjectPart,
|
2016-12-16 13:12:04 +01:00
|
|
|
config.stickToPreviousProjectPart,
|
|
|
|
|
activeProject);
|
2014-07-30 17:37:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace CppTools
|