CppEditor: Modernize

modernize-orgad
modernize-return-braced-init-list
modernize-use-auto
modernize-use-default-member-init
modernize-use-equals-default
modernize-use-nullptr
modernize-use-override
modernize-use-using

Change-Id: Ifa862782fb7b56ed3f93d9f98685c3af616797c2
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Nikolai Kosjar
2019-02-07 11:04:13 +01:00
parent 49afb01e0a
commit e0c7722441
25 changed files with 341 additions and 402 deletions

View File

@@ -33,8 +33,6 @@ namespace Internal {
class CppAutoCompleter : public TextEditor::AutoCompleter class CppAutoCompleter : public TextEditor::AutoCompleter
{ {
public: public:
CppAutoCompleter() {}
bool contextAllowsAutoBrackets(const QTextCursor &cursor, bool contextAllowsAutoBrackets(const QTextCursor &cursor,
const QString &textToInsert = QString()) const override; const QString &textToInsert = QString()) const override;
bool contextAllowsAutoQuotes(const QTextCursor &cursor, bool contextAllowsAutoQuotes(const QTextCursor &cursor,

View File

@@ -85,8 +85,6 @@ QSizePolicy sizePolicyWithStretchFactor(int stretchFactor)
class DepthFinder : public SymbolVisitor { class DepthFinder : public SymbolVisitor {
public: public:
DepthFinder() : m_symbol(0), m_depth(-1), m_foundDepth(-1), m_stop(false) {}
int operator()(const Document::Ptr &document, Symbol *symbol) int operator()(const Document::Ptr &document, Symbol *symbol)
{ {
m_symbol = symbol; m_symbol = symbol;
@@ -94,7 +92,7 @@ public:
return m_foundDepth; return m_foundDepth;
} }
bool preVisit(Symbol *symbol) bool preVisit(Symbol *symbol) override
{ {
if (m_stop) if (m_stop)
return false; return false;
@@ -111,17 +109,17 @@ public:
return false; return false;
} }
void postVisit(Symbol *symbol) void postVisit(Symbol *symbol) override
{ {
if (symbol->asScope()) if (symbol->asScope())
--m_depth; --m_depth;
} }
private: private:
Symbol *m_symbol; Symbol *m_symbol = nullptr;
int m_depth; int m_depth = -1;
int m_foundDepth; int m_foundDepth = -1;
bool m_stop; bool m_stop = false;
}; };
} // anonymous namespace } // anonymous namespace
@@ -169,12 +167,12 @@ FilterableView::FilterableView(QWidget *parent)
QPushButton *clearButton = new QPushButton(QLatin1String("&Clear"), this); QPushButton *clearButton = new QPushButton(QLatin1String("&Clear"), this);
QObject::connect(clearButton, &QAbstractButton::clicked, this, &FilterableView::clearFilter); QObject::connect(clearButton, &QAbstractButton::clicked, this, &FilterableView::clearFilter);
QHBoxLayout *filterBarLayout = new QHBoxLayout(); auto filterBarLayout = new QHBoxLayout();
filterBarLayout->addWidget(label); filterBarLayout->addWidget(label);
filterBarLayout->addWidget(lineEdit); filterBarLayout->addWidget(lineEdit);
filterBarLayout->addWidget(clearButton); filterBarLayout->addWidget(clearButton);
QVBoxLayout *mainLayout = new QVBoxLayout(); auto mainLayout = new QVBoxLayout();
mainLayout->addWidget(view); mainLayout->addWidget(view);
mainLayout->addLayout(filterBarLayout); mainLayout->addLayout(filterBarLayout);
@@ -222,10 +220,10 @@ public:
enum Columns { FileKindColumn, FilePathColumn, ColumnCount }; enum Columns { FileKindColumn, FilePathColumn, ColumnCount };
int rowCount(const QModelIndex &parent = QModelIndex()) const; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
private: private:
ProjectFiles m_files; ProjectFiles m_files;
@@ -305,10 +303,10 @@ public:
enum Columns { TypeColumn, PathColumn, ColumnCount }; enum Columns { TypeColumn, PathColumn, ColumnCount };
int rowCount(const QModelIndex &parent = QModelIndex()) const; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
private: private:
ProjectExplorer::HeaderPaths m_paths; ProjectExplorer::HeaderPaths m_paths;
@@ -377,7 +375,7 @@ class KeyValueModel : public QAbstractListModel
{ {
Q_OBJECT Q_OBJECT
public: public:
typedef QList<QPair<QString, QString> > Table; using Table = QList<QPair<QString, QString>>;
KeyValueModel(QObject *parent); KeyValueModel(QObject *parent);
void configure(const Table &table); void configure(const Table &table);
@@ -385,10 +383,10 @@ public:
enum Columns { KeyColumn, ValueColumn, ColumnCount }; enum Columns { KeyColumn, ValueColumn, ColumnCount };
int rowCount(const QModelIndex &parent = QModelIndex()) const; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
private: private:
Table m_table; Table m_table;
@@ -465,10 +463,10 @@ public:
enum Columns { SymbolCountColumn, SharedColumn, FilePathColumn, ColumnCount }; enum Columns { SymbolCountColumn, SharedColumn, FilePathColumn, ColumnCount };
int rowCount(const QModelIndex &parent = QModelIndex()) const; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
private: private:
QList<Document::Ptr> m_documents; QList<Document::Ptr> m_documents;
@@ -498,7 +496,7 @@ QModelIndex SnapshotModel::indexForDocument(const QString &filePath)
if (document->fileName() == filePath) if (document->fileName() == filePath)
return index(i, FilePathColumn); return index(i, FilePathColumn);
} }
return QModelIndex(); return {};
} }
int SnapshotModel::rowCount(const QModelIndex &/*parent*/) const int SnapshotModel::rowCount(const QModelIndex &/*parent*/) const
@@ -565,10 +563,10 @@ public:
enum Columns { ResolvedOrNotColumn, LineNumberColumn, FilePathsColumn, ColumnCount }; enum Columns { ResolvedOrNotColumn, LineNumberColumn, FilePathsColumn, ColumnCount };
int rowCount(const QModelIndex &parent = QModelIndex()) const; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
private: private:
QList<Document::Include> m_includes; QList<Document::Include> m_includes;
@@ -667,10 +665,10 @@ public:
enum Columns { LevelColumn, LineColumnNumberColumn, MessageColumn, ColumnCount }; enum Columns { LevelColumn, LineColumnNumberColumn, MessageColumn, ColumnCount };
int rowCount(const QModelIndex &parent = QModelIndex()) const; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
private: private:
QList<Document::DiagnosticMessage> m_messages; QList<Document::DiagnosticMessage> m_messages;
@@ -716,8 +714,7 @@ QVariant DiagnosticMessagesModel::data(const QModelIndex &index, int role) const
static const QBrush darkRedBrushQColor(QColor(139, 0, 0)); static const QBrush darkRedBrushQColor(QColor(139, 0, 0));
const Document::DiagnosticMessage message = m_messages.at(index.row()); const Document::DiagnosticMessage message = m_messages.at(index.row());
const Document::DiagnosticMessage::Level level const auto level = static_cast<Document::DiagnosticMessage::Level>(message.level());
= static_cast<Document::DiagnosticMessage::Level>(message.level());
if (role == Qt::DisplayRole) { if (role == Qt::DisplayRole) {
const int column = index.column(); const int column = index.column();
@@ -775,10 +772,10 @@ public:
enum Columns { LineNumberColumn, MacroColumn, ColumnCount }; enum Columns { LineNumberColumn, MacroColumn, ColumnCount };
int rowCount(const QModelIndex &parent = QModelIndex()) const; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
private: private:
QList<CPlusPlus::Macro> m_macros; QList<CPlusPlus::Macro> m_macros;
@@ -854,12 +851,12 @@ public:
enum Columns { SymbolColumn, LineNumberColumn, ColumnCount }; enum Columns { SymbolColumn, LineNumberColumn, ColumnCount };
QModelIndex index(int row, int column, const QModelIndex &parent) const; QModelIndex index(int row, int column, const QModelIndex &parent) const override;
QModelIndex parent(const QModelIndex &child) const; QModelIndex parent(const QModelIndex &child) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
private: private:
Document::Ptr m_document; Document::Ptr m_document;
@@ -886,21 +883,19 @@ void SymbolsModel::clear()
static Symbol *indexToSymbol(const QModelIndex &index) static Symbol *indexToSymbol(const QModelIndex &index)
{ {
if (Symbol *symbol = static_cast<Symbol*>(index.internalPointer())) return static_cast<Symbol*>(index.internalPointer());
return symbol;
return 0;
} }
static Scope *indexToScope(const QModelIndex &index) static Scope *indexToScope(const QModelIndex &index)
{ {
if (Symbol *symbol = indexToSymbol(index)) if (Symbol *symbol = indexToSymbol(index))
return symbol->asScope(); return symbol->asScope();
return 0; return nullptr;
} }
QModelIndex SymbolsModel::index(int row, int column, const QModelIndex &parent) const QModelIndex SymbolsModel::index(int row, int column, const QModelIndex &parent) const
{ {
Scope *scope = 0; Scope *scope = nullptr;
if (parent.isValid()) if (parent.isValid())
scope = indexToScope(parent); scope = indexToScope(parent);
else if (m_document) else if (m_document)
@@ -911,13 +906,13 @@ QModelIndex SymbolsModel::index(int row, int column, const QModelIndex &parent)
return createIndex(row, column, scope->memberAt(row)); return createIndex(row, column, scope->memberAt(row));
} }
return QModelIndex(); return {};
} }
QModelIndex SymbolsModel::parent(const QModelIndex &child) const QModelIndex SymbolsModel::parent(const QModelIndex &child) const
{ {
if (!child.isValid()) if (!child.isValid())
return QModelIndex(); return {};
if (Symbol *symbol = indexToSymbol(child)) { if (Symbol *symbol = indexToSymbol(child)) {
if (Scope *scope = symbol->enclosingScope()) { if (Scope *scope = symbol->enclosingScope()) {
@@ -926,7 +921,7 @@ QModelIndex SymbolsModel::parent(const QModelIndex &child) const
} }
} }
return QModelIndex(); return {};
} }
int SymbolsModel::rowCount(const QModelIndex &parent) const int SymbolsModel::rowCount(const QModelIndex &parent) const
@@ -994,10 +989,10 @@ public:
BytesAndCodePointsColumn, GeneratedColumn, ExpandedColumn, WhiteSpaceColumn, BytesAndCodePointsColumn, GeneratedColumn, ExpandedColumn, WhiteSpaceColumn,
NewlineColumn, ColumnCount }; NewlineColumn, ColumnCount };
int rowCount(const QModelIndex &parent = QModelIndex()) const; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
private: private:
struct TokenInfo { struct TokenInfo {
@@ -1126,10 +1121,10 @@ public:
enum Columns { PartNameColumn, PartFilePathColumn, ColumnCount }; enum Columns { PartNameColumn, PartFilePathColumn, ColumnCount };
int rowCount(const QModelIndex &parent = QModelIndex()) const; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
private: private:
QList<ProjectPart::Ptr> m_projectPartsList; QList<ProjectPart::Ptr> m_projectPartsList;
@@ -1161,7 +1156,7 @@ void ProjectPartsModel::configure(const QList<ProjectInfo> &projectInfos,
QModelIndex ProjectPartsModel::indexForCurrentEditorsProjectPart() const QModelIndex ProjectPartsModel::indexForCurrentEditorsProjectPart() const
{ {
if (m_currentEditorsProjectPartIndex == -1) if (m_currentEditorsProjectPartIndex == -1)
return QModelIndex(); return {};
return createIndex(m_currentEditorsProjectPartIndex, PartFilePathColumn); return createIndex(m_currentEditorsProjectPartIndex, PartFilePathColumn);
} }
@@ -1232,10 +1227,10 @@ public:
enum Columns { RevisionColumn, FilePathColumn, ColumnCount }; enum Columns { RevisionColumn, FilePathColumn, ColumnCount };
int rowCount(const QModelIndex &parent = QModelIndex()) const; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
private: private:
struct WorkingCopyEntry { struct WorkingCopyEntry {
@@ -1275,7 +1270,7 @@ QModelIndex WorkingCopyModel::indexForFile(const QString &filePath)
if (entry.filePath == filePath) if (entry.filePath == filePath)
return index(i, FilePathColumn); return index(i, FilePathColumn);
} }
return QModelIndex(); return {};
} }
int WorkingCopyModel::rowCount(const QModelIndex &/*parent*/) const int WorkingCopyModel::rowCount(const QModelIndex &/*parent*/) const
@@ -1542,11 +1537,11 @@ void CppCodeModelInspectorDialog::refresh()
dumper.dumpSnapshot(globalSnapshot, globalSnapshotTitle, /*isGlobalSnapshot=*/ true); dumper.dumpSnapshot(globalSnapshot, globalSnapshotTitle, /*isGlobalSnapshot=*/ true);
TextEditor::BaseTextEditor *editor = currentEditor(); TextEditor::BaseTextEditor *editor = currentEditor();
CppTools::CppEditorDocumentHandle *cppEditorDocument = 0; CppTools::CppEditorDocumentHandle *cppEditorDocument = nullptr;
if (editor) { if (editor) {
const QString editorFilePath = editor->document()->filePath().toString(); const QString editorFilePath = editor->document()->filePath().toString();
cppEditorDocument = cmmi->cppEditorDocument(editorFilePath); cppEditorDocument = cmmi->cppEditorDocument(editorFilePath);
if (auto *documentProcessor = CppToolsBridge::baseEditorDocumentProcessor(editorFilePath)) { if (auto documentProcessor = CppToolsBridge::baseEditorDocumentProcessor(editorFilePath)) {
const Snapshot editorSnapshot = documentProcessor->snapshot(); const Snapshot editorSnapshot = documentProcessor->snapshot();
m_snapshotInfos->append(SnapshotInfo(editorSnapshot, SnapshotInfo::EditorSnapshot)); m_snapshotInfos->append(SnapshotInfo(editorSnapshot, SnapshotInfo::EditorSnapshot));
const QString editorSnapshotTitle const QString editorSnapshotTitle
@@ -1555,7 +1550,7 @@ void CppCodeModelInspectorDialog::refresh()
dumper.dumpSnapshot(editorSnapshot, editorSnapshotTitle); dumper.dumpSnapshot(editorSnapshot, editorSnapshotTitle);
m_ui->snapshotSelector->addItem(editorSnapshotTitle); m_ui->snapshotSelector->addItem(editorSnapshotTitle);
} }
CppEditorWidget *cppEditorWidget = qobject_cast<CppEditorWidget *>(editor->editorWidget()); auto cppEditorWidget = qobject_cast<CppEditorWidget *>(editor->editorWidget());
if (cppEditorWidget) { if (cppEditorWidget) {
SemanticInfo semanticInfo = cppEditorWidget->semanticInfo(); SemanticInfo semanticInfo = cppEditorWidget->semanticInfo();
Snapshot snapshot; Snapshot snapshot;
@@ -1855,7 +1850,7 @@ void CppCodeModelInspectorDialog::updateProjectPartData(const ProjectPart::Ptr &
bool CppCodeModelInspectorDialog::event(QEvent *e) bool CppCodeModelInspectorDialog::event(QEvent *e)
{ {
if (e->type() == QEvent::ShortcutOverride) { if (e->type() == QEvent::ShortcutOverride) {
QKeyEvent *ke = static_cast<QKeyEvent *>(e); auto ke = static_cast<QKeyEvent *>(e);
if (ke->key() == Qt::Key_Escape && !ke->modifiers()) { if (ke->key() == Qt::Key_Escape && !ke->modifiers()) {
ke->accept(); ke->accept();
close(); close();

View File

@@ -65,8 +65,8 @@ class CppCodeModelInspectorDialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit CppCodeModelInspectorDialog(QWidget *parent = 0); explicit CppCodeModelInspectorDialog(QWidget *parent = nullptr);
~CppCodeModelInspectorDialog(); ~CppCodeModelInspectorDialog() override;
private: private:
void onRefreshRequested(); void onRefreshRequested();
@@ -90,7 +90,7 @@ private:
void clearProjectPartData(); void clearProjectPartData();
void updateProjectPartData(const CppTools::ProjectPart::Ptr &part); void updateProjectPartData(const CppTools::ProjectPart::Ptr &part);
bool event(QEvent *e); bool event(QEvent *e) override;
private: private:
Ui::CppCodeModelInspectorDialog *m_ui; Ui::CppCodeModelInspectorDialog *m_ui;

View File

@@ -80,7 +80,10 @@ public:
mm()->registerCppEditorDocument(this); mm()->registerCppEditorDocument(this);
} }
~CppEditorDocumentHandleImpl() { mm()->unregisterCppEditorDocument(m_registrationFilePath); } ~CppEditorDocumentHandleImpl() override
{
mm()->unregisterCppEditorDocument(m_registrationFilePath);
}
QString filePath() const override { return m_cppEditorDocument->filePath().toString(); } QString filePath() const override { return m_cppEditorDocument->filePath().toString(); }
QByteArray contents() const override { return m_cppEditorDocument->contentsText(); } QByteArray contents() const override { return m_cppEditorDocument->contentsText(); }
@@ -100,12 +103,7 @@ private:
}; };
CppEditorDocument::CppEditorDocument() CppEditorDocument::CppEditorDocument()
: m_fileIsBeingReloaded(false) : m_minimizableInfoBars(*infoBar())
, m_isObjCEnabled(false)
, m_cachedContentsRevision(-1)
, m_processorRevision(0)
, m_completionAssistProvider(0)
, m_minimizableInfoBars(*infoBar())
{ {
setId(CppEditor::Constants::CPPEDITOR_ID); setId(CppEditor::Constants::CPPEDITOR_ID);
setSyntaxHighlighter(new CppHighlighter); setSyntaxHighlighter(new CppHighlighter);
@@ -352,7 +350,7 @@ unsigned CppEditorDocument::contentsRevision() const
void CppEditorDocument::releaseResources() void CppEditorDocument::releaseResources()
{ {
if (m_processor) if (m_processor)
disconnect(m_processor.data(), 0, this, 0); disconnect(m_processor.data(), nullptr, this, nullptr);
m_processor.reset(); m_processor.reset();
} }

View File

@@ -115,19 +115,19 @@ private:
void initializeTimer(); void initializeTimer();
private: private:
bool m_fileIsBeingReloaded; bool m_fileIsBeingReloaded = false;
bool m_isObjCEnabled; bool m_isObjCEnabled = false;
// Caching contents // Caching contents
mutable QMutex m_cachedContentsLock; mutable QMutex m_cachedContentsLock;
mutable QByteArray m_cachedContents; mutable QByteArray m_cachedContents;
mutable int m_cachedContentsRevision; mutable int m_cachedContentsRevision = -1;
unsigned m_processorRevision; unsigned m_processorRevision = 0;
QTimer m_processorTimer; QTimer m_processorTimer;
QScopedPointer<CppTools::BaseEditorDocumentProcessor> m_processor; QScopedPointer<CppTools::BaseEditorDocumentProcessor> m_processor;
CppTools::CppCompletionAssistProvider *m_completionAssistProvider; CppTools::CppCompletionAssistProvider *m_completionAssistProvider = nullptr;
// (Un)Registration in CppModelManager // (Un)Registration in CppModelManager
QScopedPointer<CppTools::CppEditorDocumentHandle> m_editorDocumentHandle; QScopedPointer<CppTools::CppEditorDocumentHandle> m_editorDocumentHandle;

View File

@@ -310,7 +310,7 @@ static CppEditorWidget *currentCppEditorWidget()
{ {
if (IEditor *currentEditor = EditorManager::currentEditor()) if (IEditor *currentEditor = EditorManager::currentEditor())
return qobject_cast<CppEditorWidget*>(currentEditor->widget()); return qobject_cast<CppEditorWidget*>(currentEditor->widget());
return 0; return nullptr;
} }
void CppEditorPlugin::switchDeclarationDefinition() void CppEditorPlugin::switchDeclarationDefinition()

View File

@@ -40,7 +40,7 @@ class CppEditorPlugin : public ExtensionSystem::IPlugin
public: public:
CppEditorPlugin(); CppEditorPlugin();
~CppEditorPlugin(); ~CppEditorPlugin() override;
static CppEditorPlugin *instance(); static CppEditorPlugin *instance();

View File

@@ -261,7 +261,7 @@ void CppEditorWidget::finalizeInitialization()
void CppEditorWidget::finalizeInitializationAfterDuplication(TextEditorWidget *other) void CppEditorWidget::finalizeInitializationAfterDuplication(TextEditorWidget *other)
{ {
QTC_ASSERT(other, return); QTC_ASSERT(other, return);
CppEditorWidget *cppEditorWidget = qobject_cast<CppEditorWidget *>(other); auto cppEditorWidget = qobject_cast<CppEditorWidget *>(other);
QTC_ASSERT(cppEditorWidget, return); QTC_ASSERT(cppEditorWidget, return);
if (cppEditorWidget->isSemanticInfoValidExceptLocalUses()) if (cppEditorWidget->isSemanticInfoValidExceptLocalUses())
@@ -278,10 +278,7 @@ void CppEditorWidget::finalizeInitializationAfterDuplication(TextEditorWidget *o
d->m_cppEditorDocument->parseContextModel().areMultipleAvailable()); d->m_cppEditorDocument->parseContextModel().areMultipleAvailable());
} }
CppEditorWidget::~CppEditorWidget() CppEditorWidget::~CppEditorWidget() = default;
{
// non-inline destructor, see section "Forward Declared Pointers" of QScopedPointer.
}
CppEditorDocument *CppEditorWidget::cppEditorDocument() const CppEditorDocument *CppEditorWidget::cppEditorDocument() const
{ {
@@ -357,7 +354,7 @@ static QString getDocumentLine(const QTextDocument &document, int line)
static QString getFileLine(const QString &path, int line) static QString getFileLine(const QString &path, int line)
{ {
const IDocument *document = DocumentModel::documentForFilePath(path); const IDocument *document = DocumentModel::documentForFilePath(path);
const TextDocument *textDocument = qobject_cast<const TextDocument *>(document); const auto textDocument = qobject_cast<const TextDocument *>(document);
if (textDocument) if (textDocument)
return getDocumentLine(*textDocument->document(), line); return getDocumentLine(*textDocument->document(), line);
@@ -543,7 +540,7 @@ ProjectPart *findProjectPartForCurrentProject(const QList<ProjectPart::Ptr> &pro
if (found != projectParts.cend()) if (found != projectParts.cend())
return (*found).data(); return (*found).data();
return 0; return nullptr;
} }
} // namespace } // namespace
@@ -551,7 +548,7 @@ ProjectPart *findProjectPartForCurrentProject(const QList<ProjectPart::Ptr> &pro
ProjectPart *CppEditorWidget::projectPart() const ProjectPart *CppEditorWidget::projectPart() const
{ {
if (!d->m_modelManager) if (!d->m_modelManager)
return 0; return nullptr;
auto projectParts = fetchProjectParts(d->m_modelManager, textDocument()->filePath()); auto projectParts = fetchProjectParts(d->m_modelManager, textDocument()->filePath());
@@ -668,8 +665,8 @@ void CppEditorWidget::switchDeclarationDefinition(bool inNextSplit)
return; return;
// Find function declaration or definition under cursor // Find function declaration or definition under cursor
Function *functionDefinitionSymbol = 0; Function *functionDefinitionSymbol = nullptr;
Symbol *functionDeclarationSymbol = 0; Symbol *functionDeclarationSymbol = nullptr;
ASTPath astPathFinder(d->m_lastSemanticInfo.doc); ASTPath astPathFinder(d->m_lastSemanticInfo.doc);
const QList<AST *> astPath = astPathFinder(textCursor()); const QList<AST *> astPath = astPathFinder(textCursor());
@@ -998,7 +995,7 @@ AssistInterface *CppEditorWidget::createAssistInterface(AssistKind kind, AssistR
} else { } else {
return TextEditorWidget::createAssistInterface(kind, reason); return TextEditorWidget::createAssistInterface(kind, reason);
} }
return 0; return nullptr;
} }
QSharedPointer<FunctionDeclDefLink> CppEditorWidget::declDefLink() const QSharedPointer<FunctionDeclDefLink> CppEditorWidget::declDefLink() const

View File

@@ -96,19 +96,17 @@ static bool findDeclOrDef(const Document::Ptr &doc, int line, int column,
// by CompoundStatement/CtorInitializer // by CompoundStatement/CtorInitializer
// for function declarations, look for SimpleDeclarations with a single Declarator // for function declarations, look for SimpleDeclarations with a single Declarator
// with a FunctionDeclarator postfix // with a FunctionDeclarator postfix
FunctionDefinitionAST *funcDef = 0; *decl = nullptr;
SimpleDeclarationAST *simpleDecl = 0;
*decl = 0;
for (int i = path.size() - 1; i > 0; --i) { for (int i = path.size() - 1; i > 0; --i) {
AST *ast = path.at(i); AST *ast = path.at(i);
if (ast->asCompoundStatement() || ast->asCtorInitializer()) if (ast->asCompoundStatement() || ast->asCtorInitializer())
break; break;
if ((funcDef = ast->asFunctionDefinition()) != 0) { if (FunctionDefinitionAST *funcDef = ast->asFunctionDefinition()) {
*parent = funcDef; *parent = funcDef;
*decl = funcDef->declarator; *decl = funcDef->declarator;
break; break;
} }
if ((simpleDecl = ast->asSimpleDeclaration()) != 0) { if (SimpleDeclarationAST *simpleDecl = ast->asSimpleDeclaration()) {
*parent = simpleDecl; *parent = simpleDecl;
if (!simpleDecl->declarator_list || !simpleDecl->declarator_list->value) if (!simpleDecl->declarator_list || !simpleDecl->declarator_list->value)
break; break;
@@ -142,12 +140,12 @@ static void declDefLinkStartEnd(const CppRefactoringFileConstPtr &file,
static DeclaratorIdAST *getDeclaratorId(DeclaratorAST *declarator) static DeclaratorIdAST *getDeclaratorId(DeclaratorAST *declarator)
{ {
if (!declarator || !declarator->core_declarator) if (!declarator || !declarator->core_declarator)
return 0; return nullptr;
if (DeclaratorIdAST *id = declarator->core_declarator->asDeclaratorId()) if (DeclaratorIdAST *id = declarator->core_declarator->asDeclaratorId())
return id; return id;
if (NestedDeclaratorAST *nested = declarator->core_declarator->asNestedDeclarator()) if (NestedDeclaratorAST *nested = declarator->core_declarator->asNestedDeclarator())
return getDeclaratorId(nested->declarator); return getDeclaratorId(nested->declarator);
return 0; return nullptr;
} }
static QSharedPointer<FunctionDeclDefLink> findLinkHelper(QSharedPointer<FunctionDeclDefLink> link, CppRefactoringChanges changes) static QSharedPointer<FunctionDeclDefLink> findLinkHelper(QSharedPointer<FunctionDeclDefLink> link, CppRefactoringChanges changes)
@@ -156,7 +154,7 @@ static QSharedPointer<FunctionDeclDefLink> findLinkHelper(QSharedPointer<Functio
const Snapshot &snapshot = changes.snapshot(); const Snapshot &snapshot = changes.snapshot();
// find the matching decl/def symbol // find the matching decl/def symbol
Symbol *target = 0; Symbol *target = nullptr;
SymbolFinder finder; SymbolFinder finder;
if (FunctionDefinitionAST *funcDef = link->sourceDeclaration->asFunctionDefinition()) { if (FunctionDefinitionAST *funcDef = link->sourceDeclaration->asFunctionDefinition()) {
QList<Declaration *> nameMatch, argumentCountMatch, typeMatch; QList<Declaration *> nameMatch, argumentCountMatch, typeMatch;
@@ -178,9 +176,9 @@ static QSharedPointer<FunctionDeclDefLink> findLinkHelper(QSharedPointer<Functio
if (!targetFile->isValid()) if (!targetFile->isValid())
return noResult; return noResult;
DeclarationAST *targetParent = 0; DeclarationAST *targetParent = nullptr;
FunctionDeclaratorAST *targetFuncDecl = 0; FunctionDeclaratorAST *targetFuncDecl = nullptr;
DeclaratorAST *targetDeclarator = 0; DeclaratorAST *targetDeclarator = nullptr;
if (!findDeclOrDef(targetFile->cppDocument(), target->line(), target->column(), if (!findDeclOrDef(targetFile->cppDocument(), target->line(), target->column(),
&targetParent, &targetDeclarator, &targetFuncDecl)) &targetParent, &targetDeclarator, &targetFuncDecl))
return noResult; return noResult;
@@ -213,9 +211,9 @@ void FunctionDeclDefLinkFinder::startFindLinkAt(
QTextCursor cursor, const Document::Ptr &doc, const Snapshot &snapshot) QTextCursor cursor, const Document::Ptr &doc, const Snapshot &snapshot)
{ {
// check if cursor is on function decl/def // check if cursor is on function decl/def
DeclarationAST *parent = 0; DeclarationAST *parent = nullptr;
FunctionDeclaratorAST *funcDecl = 0; FunctionDeclaratorAST *funcDecl = nullptr;
DeclaratorAST *declarator = 0; DeclaratorAST *declarator = nullptr;
if (!findDeclOrDef(doc, cursor.blockNumber() + 1, cursor.columnNumber() + 1, if (!findDeclOrDef(doc, cursor.blockNumber() + 1, cursor.columnNumber() + 1,
&parent, &declarator, &funcDecl)) &parent, &declarator, &funcDecl))
return; return;
@@ -455,10 +453,10 @@ static SpecifierAST *findFirstReplaceableSpecifier(TranslationUnit *translationU
if (canReplaceSpecifier(translationUnit, it->value)) if (canReplaceSpecifier(translationUnit, it->value))
return it->value; return it->value;
} }
return 0; return nullptr;
} }
typedef QVarLengthArray<int, 10> IndicesList; using IndicesList = QVarLengthArray<int, 10>;
template <class IndicesListType> template <class IndicesListType>
static int findUniqueTypeMatch(int sourceParamIndex, Function *sourceFunction, Function *newFunction, static int findUniqueTypeMatch(int sourceParamIndex, Function *sourceFunction, Function *newFunction,
@@ -597,8 +595,8 @@ ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot, int targetOffse
Control *control = sourceContext.bindings()->control().data(); Control *control = sourceContext.bindings()->control().data();
// get return type start position and declarator info from declaration // get return type start position and declarator info from declaration
DeclaratorAST *declarator = 0; DeclaratorAST *declarator = nullptr;
SpecifierAST *firstReplaceableSpecifier = 0; SpecifierAST *firstReplaceableSpecifier = nullptr;
TranslationUnit *targetTranslationUnit = targetFile->cppDocument()->translationUnit(); TranslationUnit *targetTranslationUnit = targetFile->cppDocument()->translationUnit();
if (SimpleDeclarationAST *simple = targetDeclaration->asSimpleDeclaration()) { if (SimpleDeclarationAST *simple = targetDeclaration->asSimpleDeclaration()) {
declarator = simple->declarator_list->value; declarator = simple->declarator_list->value;
@@ -790,7 +788,7 @@ ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot, int targetOffse
if (hasCommentedName(targetFile->cppDocument()->translationUnit(), if (hasCommentedName(targetFile->cppDocument()->translationUnit(),
QString::fromUtf8(targetFile->cppDocument()->utf8Source()), QString::fromUtf8(targetFile->cppDocument()->utf8Source()),
targetFunctionDeclarator, existingParamIndex)) targetFunctionDeclarator, existingParamIndex))
replacementName = 0; replacementName = nullptr;
// track renames // track renames
if (replacementName != targetParam->name() && replacementName) if (replacementName != targetParam->name() && replacementName)
@@ -914,8 +912,8 @@ ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot, int targetOffse
changes.insert(targetFile->endOf(targetFunctionDeclarator->rparen_token), cvString); changes.insert(targetFile->endOf(targetFunctionDeclarator->rparen_token), cvString);
// modify/remove existing specifiers // modify/remove existing specifiers
} else { } else {
SimpleSpecifierAST *constSpecifier = 0; SimpleSpecifierAST *constSpecifier = nullptr;
SimpleSpecifierAST *volatileSpecifier = 0; SimpleSpecifierAST *volatileSpecifier = nullptr;
for (SpecifierListAST *it = targetFunctionDeclarator->cv_qualifier_list; it; it = it->next) { for (SpecifierListAST *it = targetFunctionDeclarator->cv_qualifier_list; it; it = it->next) {
if (SimpleSpecifierAST *simple = it->value->asSimpleSpecifier()) { if (SimpleSpecifierAST *simple = it->value->asSimpleSpecifier()) {
unsigned kind = targetFile->tokenAt(simple->specifier_token).kind(); unsigned kind = targetFile->tokenAt(simple->specifier_token).kind();

View File

@@ -45,7 +45,7 @@ class FunctionDeclDefLinkFinder : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
FunctionDeclDefLinkFinder(QObject *parent = 0); FunctionDeclDefLinkFinder(QObject *parent = nullptr);
void startFindLinkAt(QTextCursor cursor, void startFindLinkAt(QTextCursor cursor,
const CPlusPlus::Document::Ptr &doc, const CPlusPlus::Document::Ptr &doc,

View File

@@ -41,7 +41,7 @@ class CppHighlighter : public TextEditor::SyntaxHighlighter
Q_OBJECT Q_OBJECT
public: public:
CppHighlighter(QTextDocument *document = 0); CppHighlighter(QTextDocument *document = nullptr);
void setLanguageFeatures(const CPlusPlus::LanguageFeatures &languageFeatures); void setLanguageFeatures(const CPlusPlus::LanguageFeatures &languageFeatures);
void highlightBlock(const QString &text) override; void highlightBlock(const QString &text) override;

View File

@@ -80,7 +80,7 @@ static Snapshot globalSnapshot()
struct FileAndLine struct FileAndLine
{ {
FileAndLine() {} FileAndLine() = default;
FileAndLine(const QString &f, int l) : file(f), line(l) {} FileAndLine(const QString &f, int l) : file(f), line(l) {}
QString file; QString file;
@@ -122,7 +122,7 @@ class CppIncludeHierarchyItem
{ {
public: public:
enum SubTree { RootItem, InIncludes, InIncludedBy }; enum SubTree { RootItem, InIncludes, InIncludedBy };
CppIncludeHierarchyItem() {} CppIncludeHierarchyItem() = default;
void createChild(const QString &filePath, SubTree subTree, void createChild(const QString &filePath, SubTree subTree,
int line = 0, bool definitelyNoChildren = false) int line = 0, bool definitelyNoChildren = false)
@@ -348,7 +348,7 @@ class CppIncludeHierarchyWidget : public QWidget
public: public:
CppIncludeHierarchyWidget(); CppIncludeHierarchyWidget();
~CppIncludeHierarchyWidget() { delete m_treeView; } ~CppIncludeHierarchyWidget() override { delete m_treeView; }
void perform(); void perform();

View File

@@ -38,7 +38,7 @@ class CppIncludeHierarchyItem;
class CppIncludeHierarchyModel : public Utils::TreeModel<CppIncludeHierarchyItem> class CppIncludeHierarchyModel : public Utils::TreeModel<CppIncludeHierarchyItem>
{ {
Q_OBJECT Q_OBJECT
typedef Utils::TreeModel<CppIncludeHierarchyItem> base_type; using base_type = Utils::TreeModel<CppIncludeHierarchyItem>;
public: public:
CppIncludeHierarchyModel(); CppIncludeHierarchyModel();

View File

@@ -92,8 +92,8 @@ public:
ModeImplementationFile = 0x00000008 ModeImplementationFile = 0x00000008
}; };
InsertVirtualMethodsDialog(QWidget *parent = 0); InsertVirtualMethodsDialog(QWidget *parent = nullptr);
~InsertVirtualMethodsDialog(); ~InsertVirtualMethodsDialog() override;
void initGui(); void initGui();
void initData(); void initData();
virtual void saveSettings(); virtual void saveSettings();
@@ -113,20 +113,20 @@ private:
void updateOverrideReplacementsComboBox(); void updateOverrideReplacementsComboBox();
private: private:
QTreeView *m_view; QTreeView *m_view = nullptr;
QLineEdit *m_filter; QLineEdit *m_filter = nullptr;
QCheckBox *m_hideReimplementedFunctions; QCheckBox *m_hideReimplementedFunctions = nullptr;
QComboBox *m_insertMode; QComboBox *m_insertMode = nullptr;
QCheckBox *m_virtualKeyword; QCheckBox *m_virtualKeyword = nullptr;
QCheckBox *m_overrideReplacementCheckBox; QCheckBox *m_overrideReplacementCheckBox = nullptr;
QComboBox *m_overrideReplacementComboBox; QComboBox *m_overrideReplacementComboBox = nullptr;
QToolButton *m_clearUserAddedReplacementsButton; QToolButton *m_clearUserAddedReplacementsButton = nullptr;
QDialogButtonBox *m_buttons; QDialogButtonBox *m_buttons = nullptr;
QList<bool> m_expansionStateNormal; QList<bool> m_expansionStateNormal;
QList<bool> m_expansionStateReimp; QList<bool> m_expansionStateReimp;
QStringList m_availableOverrideReplacements; QStringList m_availableOverrideReplacements;
bool m_hasImplementationFile; bool m_hasImplementationFile = false;
bool m_hasReimplementedFunctions; bool m_hasReimplementedFunctions = false;
protected: protected:
VirtualMethodsSettings *m_settings; VirtualMethodsSettings *m_settings;
@@ -149,15 +149,11 @@ namespace {
class InsertVirtualMethodsItem class InsertVirtualMethodsItem
{ {
public: public:
InsertVirtualMethodsItem(InsertVirtualMethodsItem *parent) : InsertVirtualMethodsItem(InsertVirtualMethodsItem *parent)
row(-1), : m_parent(parent)
m_parent(parent) {}
{
}
virtual ~InsertVirtualMethodsItem() virtual ~InsertVirtualMethodsItem() = default;
{
}
virtual QString description() const = 0; virtual QString description() const = 0;
virtual Qt::ItemFlags flags() const = 0; virtual Qt::ItemFlags flags() const = 0;
@@ -165,10 +161,10 @@ public:
InsertVirtualMethodsItem *parent() { return m_parent; } InsertVirtualMethodsItem *parent() { return m_parent; }
int row; int row = -1;
private: private:
InsertVirtualMethodsItem *m_parent; InsertVirtualMethodsItem *m_parent = nullptr;
}; };
class FunctionItem; class FunctionItem;
@@ -177,11 +173,11 @@ class ClassItem : public InsertVirtualMethodsItem
{ {
public: public:
ClassItem(const QString &className, const Class *clazz); ClassItem(const QString &className, const Class *clazz);
~ClassItem(); ~ClassItem() override;
QString description() const { return name; } QString description() const override { return name; }
Qt::ItemFlags flags() const; Qt::ItemFlags flags() const override;
Qt::CheckState checkState() const; Qt::CheckState checkState() const override;
void removeFunction(int row); void removeFunction(int row);
const Class *klass; const Class *klass;
@@ -193,9 +189,9 @@ class FunctionItem : public InsertVirtualMethodsItem
{ {
public: public:
FunctionItem(const Function *func, const QString &functionName, ClassItem *parent); FunctionItem(const Function *func, const QString &functionName, ClassItem *parent);
QString description() const; QString description() const override;
Qt::ItemFlags flags() const; Qt::ItemFlags flags() const override;
Qt::CheckState checkState() const { return checked ? Qt::Checked : Qt::Unchecked; } Qt::CheckState checkState() const override { return checked ? Qt::Checked : Qt::Unchecked; }
const Function *function = nullptr; const Function *function = nullptr;
InsertionPointLocator::AccessSpec accessSpec = InsertionPointLocator::Invalid; InsertionPointLocator::AccessSpec accessSpec = InsertionPointLocator::Invalid;
@@ -209,7 +205,7 @@ private:
}; };
ClassItem::ClassItem(const QString &className, const Class *clazz) : ClassItem::ClassItem(const QString &className, const Class *clazz) :
InsertVirtualMethodsItem(0), InsertVirtualMethodsItem(nullptr),
klass(clazz), klass(clazz),
name(className) name(className)
{ {
@@ -339,7 +335,7 @@ public:
bool insertOverrideReplacement = false; bool insertOverrideReplacement = false;
private: private:
typedef QLatin1String _; using _ = QLatin1String;
static QString group() { return _("QuickFix/InsertVirtualMethods"); } static QString group() { return _("QuickFix/InsertVirtualMethods"); }
static QString insertVirtualKeywordKey() { return _("insertKeywordVirtual"); } static QString insertVirtualKeywordKey() { return _("insertKeywordVirtual"); }
static QString insertOverrideReplacementKey() { return _("insertOverrideReplacement"); } static QString insertOverrideReplacementKey() { return _("insertOverrideReplacement"); }
@@ -352,13 +348,13 @@ private:
class InsertVirtualMethodsModel : public QAbstractItemModel class InsertVirtualMethodsModel : public QAbstractItemModel
{ {
public: public:
InsertVirtualMethodsModel(QObject *parent = 0) : QAbstractItemModel(parent) InsertVirtualMethodsModel(QObject *parent = nullptr) : QAbstractItemModel(parent)
{ {
const FontSettings &fs = TextEditorSettings::fontSettings(); const FontSettings &fs = TextEditorSettings::fontSettings();
formatReimpFunc = fs.formatFor(C_DISABLED_CODE); formatReimpFunc = fs.formatFor(C_DISABLED_CODE);
} }
~InsertVirtualMethodsModel() ~InsertVirtualMethodsModel() override
{ {
clear(); clear();
} }
@@ -371,26 +367,26 @@ public:
endResetModel(); endResetModel();
} }
QModelIndex index(int row, int column, const QModelIndex &parent) const QModelIndex index(int row, int column, const QModelIndex &parent) const override
{ {
if (column != 0) if (column != 0)
return QModelIndex(); return {};
if (parent.isValid()) { if (parent.isValid()) {
ClassItem *classItem = static_cast<ClassItem *>(parent.internalPointer()); auto classItem = static_cast<ClassItem *>(parent.internalPointer());
return createIndex(row, column, classItem->functions.at(row)); return createIndex(row, column, classItem->functions.at(row));
} }
return createIndex(row, column, classes.at(row)); return createIndex(row, column, classes.at(row));
} }
QModelIndex parent(const QModelIndex &child) const QModelIndex parent(const QModelIndex &child) const override
{ {
if (!child.isValid()) if (!child.isValid())
return QModelIndex(); return {};
InsertVirtualMethodsItem *parent = itemForIndex(child)->parent(); InsertVirtualMethodsItem *parent = itemForIndex(child)->parent();
return parent ? createIndex(parent->row, 0, parent) : QModelIndex(); return parent ? createIndex(parent->row, 0, parent) : QModelIndex();
} }
int rowCount(const QModelIndex &parent) const int rowCount(const QModelIndex &parent) const override
{ {
if (!parent.isValid()) if (!parent.isValid())
return classes.count(); return classes.count();
@@ -400,7 +396,7 @@ public:
return static_cast<ClassItem *>(item)->functions.count(); return static_cast<ClassItem *>(item)->functions.count();
} }
int columnCount(const QModelIndex &) const int columnCount(const QModelIndex &) const override
{ {
return 1; return 1;
} }
@@ -416,13 +412,13 @@ public:
void removeFunction(FunctionItem *funcItem) void removeFunction(FunctionItem *funcItem)
{ {
ClassItem *classItem = static_cast<ClassItem *>(funcItem->parent()); auto classItem = static_cast<ClassItem *>(funcItem->parent());
beginRemoveRows(createIndex(classItem->row, 0, classItem), funcItem->row, funcItem->row); beginRemoveRows(createIndex(classItem->row, 0, classItem), funcItem->row, funcItem->row);
classItem->removeFunction(funcItem->row); classItem->removeFunction(funcItem->row);
endRemoveRows(); endRemoveRows();
} }
QVariant data(const QModelIndex &index, int role) const QVariant data(const QModelIndex &index, int role) const override
{ {
if (!index.isValid()) if (!index.isValid())
return QVariant(); return QVariant();
@@ -446,7 +442,7 @@ public:
break; break;
case InsertVirtualMethodsDialog::Reimplemented: case InsertVirtualMethodsDialog::Reimplemented:
if (item->parent()) { if (item->parent()) {
FunctionItem *function = static_cast<FunctionItem *>(item); auto function = static_cast<FunctionItem *>(item);
return QVariant(function->alreadyFound); return QVariant(function->alreadyFound);
} }
@@ -454,7 +450,7 @@ public:
return QVariant(); return QVariant();
} }
bool setData(const QModelIndex &index, const QVariant &value, int role) bool setData(const QModelIndex &index, const QVariant &value, int role) override
{ {
if (!index.isValid()) if (!index.isValid())
return false; return false;
@@ -464,7 +460,7 @@ public:
case Qt::CheckStateRole: { case Qt::CheckStateRole: {
bool checked = value.toInt() == Qt::Checked; bool checked = value.toInt() == Qt::Checked;
if (item->parent()) { if (item->parent()) {
FunctionItem *funcItem = static_cast<FunctionItem *>(item); auto funcItem = static_cast<FunctionItem *>(item);
while (funcItem->checked != checked) { while (funcItem->checked != checked) {
funcItem->checked = checked; funcItem->checked = checked;
const QModelIndex funcIndex = createIndex(funcItem->row, 0, funcItem); const QModelIndex funcIndex = createIndex(funcItem->row, 0, funcItem);
@@ -475,7 +471,7 @@ public:
funcItem = funcItem->nextOverride; funcItem = funcItem->nextOverride;
} }
} else { } else {
ClassItem *classItem = static_cast<ClassItem *>(item); auto classItem = static_cast<ClassItem *>(item);
foreach (FunctionItem *funcItem, classItem->functions) { foreach (FunctionItem *funcItem, classItem->functions) {
if (funcItem->alreadyFound || funcItem->checked == checked) if (funcItem->alreadyFound || funcItem->checked == checked)
continue; continue;
@@ -489,7 +485,7 @@ public:
return QAbstractItemModel::setData(index, value, role); return QAbstractItemModel::setData(index, value, role);
} }
Qt::ItemFlags flags(const QModelIndex &index) const Qt::ItemFlags flags(const QModelIndex &index) const override
{ {
if (!index.isValid()) if (!index.isValid())
return Qt::NoItemFlags; return Qt::NoItemFlags;
@@ -586,7 +582,7 @@ public:
if (!name || name->asDestructorNameId()) if (!name || name->asDestructorNameId())
continue; continue;
const Function *firstVirtual = 0; const Function *firstVirtual = nullptr;
const bool isVirtual = FunctionUtils::isVirtualFunction( const bool isVirtual = FunctionUtils::isVirtualFunction(
func, interface.context(), &firstVirtual); func, interface.context(), &firstVirtual);
if (!isVirtual) if (!isVirtual)
@@ -594,7 +590,7 @@ public:
if (func->isFinal()) { if (func->isFinal()) {
if (FunctionItem *first = virtualFunctions[firstVirtual]) { if (FunctionItem *first = virtualFunctions[firstVirtual]) {
FunctionItem *next = 0; FunctionItem *next = nullptr;
for (FunctionItem *removed = first; next != first; removed = next) { for (FunctionItem *removed = first; next != first; removed = next) {
next = removed->nextOverride; next = removed->nextOverride;
m_factory->classFunctionModel->removeFunction(removed); m_factory->classFunctionModel->removeFunction(removed);
@@ -643,7 +639,7 @@ public:
itemName += QLatin1String(" : ") + itemReturnTypeString; itemName += QLatin1String(" : ") + itemReturnTypeString;
if (isReimplemented) if (isReimplemented)
itemName += QLatin1String(" (redeclared)"); itemName += QLatin1String(" (redeclared)");
FunctionItem *funcItem = new FunctionItem(func, itemName, itemBase); auto funcItem = new FunctionItem(func, itemName, itemBase);
if (isReimplemented) { if (isReimplemented) {
factory->setHasReimplementedFunctions(true); factory->setHasReimplementedFunctions(true);
funcItem->reimplemented = true; funcItem->reimplemented = true;
@@ -734,7 +730,7 @@ public:
return spec; return spec;
} }
void perform() void perform() override
{ {
if (!m_factory->gather()) if (!m_factory->gather())
return; return;
@@ -897,12 +893,11 @@ class InsertVirtualMethodsFilterModel : public QSortFilterProxyModel
{ {
Q_OBJECT Q_OBJECT
public: public:
InsertVirtualMethodsFilterModel(QObject *parent = 0) InsertVirtualMethodsFilterModel(QObject *parent = nullptr)
: QSortFilterProxyModel(parent) : QSortFilterProxyModel(parent)
, m_hideReimplemented(false)
{} {}
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
{ {
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
@@ -941,22 +936,11 @@ public:
} }
private: private:
bool m_hideReimplemented; bool m_hideReimplemented = false;
}; };
InsertVirtualMethodsDialog::InsertVirtualMethodsDialog(QWidget *parent) InsertVirtualMethodsDialog::InsertVirtualMethodsDialog(QWidget *parent)
: QDialog(parent) : QDialog(parent)
, m_view(0)
, m_filter(0)
, m_hideReimplementedFunctions(0)
, m_insertMode(0)
, m_virtualKeyword(0)
, m_overrideReplacementCheckBox(0)
, m_overrideReplacementComboBox(0)
, m_clearUserAddedReplacementsButton(0)
, m_buttons(0)
, m_hasImplementationFile(false)
, m_hasReimplementedFunctions(false)
, m_settings(new VirtualMethodsSettings) , m_settings(new VirtualMethodsSettings)
, classFunctionModel(new InsertVirtualMethodsModel(this)) , classFunctionModel(new InsertVirtualMethodsModel(this))
, classFunctionFilterModel(new InsertVirtualMethodsFilterModel(this)) , classFunctionFilterModel(new InsertVirtualMethodsFilterModel(this))
@@ -976,11 +960,11 @@ void InsertVirtualMethodsDialog::initGui()
return; return;
setWindowTitle(tr("Insert Virtual Functions")); setWindowTitle(tr("Insert Virtual Functions"));
QVBoxLayout *globalVerticalLayout = new QVBoxLayout; auto globalVerticalLayout = new QVBoxLayout;
// View // View
QGroupBox *groupBoxView = new QGroupBox(tr("&Functions to insert:"), this); QGroupBox *groupBoxView = new QGroupBox(tr("&Functions to insert:"), this);
QVBoxLayout *groupBoxViewLayout = new QVBoxLayout(groupBoxView); auto groupBoxViewLayout = new QVBoxLayout(groupBoxView);
m_filter = new QLineEdit(this); m_filter = new QLineEdit(this);
m_filter->setClearButtonEnabled(true); m_filter->setClearButtonEnabled(true);
m_filter->setPlaceholderText(tr("Filter")); m_filter->setPlaceholderText(tr("Filter"));
@@ -995,7 +979,7 @@ void InsertVirtualMethodsDialog::initGui()
// Insertion options // Insertion options
QGroupBox *groupBoxImplementation = new QGroupBox(tr("&Insertion options:"), this); QGroupBox *groupBoxImplementation = new QGroupBox(tr("&Insertion options:"), this);
QVBoxLayout *groupBoxImplementationLayout = new QVBoxLayout(groupBoxImplementation); auto groupBoxImplementationLayout = new QVBoxLayout(groupBoxImplementation);
m_insertMode = new QComboBox(this); m_insertMode = new QComboBox(this);
m_insertMode->addItem(tr("Insert only declarations"), ModeOnlyDeclarations); m_insertMode->addItem(tr("Insert only declarations"), ModeOnlyDeclarations);
m_insertMode->addItem(tr("Insert definitions inside class"), ModeInsideClass); m_insertMode->addItem(tr("Insert definitions inside class"), ModeInsideClass);
@@ -1012,7 +996,7 @@ void InsertVirtualMethodsDialog::initGui()
connect(m_overrideReplacementCheckBox, &QCheckBox::clicked, connect(m_overrideReplacementCheckBox, &QCheckBox::clicked,
m_overrideReplacementComboBox, &QComboBox::setEnabled); m_overrideReplacementComboBox, &QComboBox::setEnabled);
QAction *clearUserAddedReplacements = new QAction(this); auto clearUserAddedReplacements = new QAction(this);
clearUserAddedReplacements->setIcon(Utils::Icons::CLEAN_TOOLBAR.icon()); clearUserAddedReplacements->setIcon(Utils::Icons::CLEAN_TOOLBAR.icon());
clearUserAddedReplacements->setText(tr("Clear Added \"override\" Equivalents")); clearUserAddedReplacements->setText(tr("Clear Added \"override\" Equivalents"));
connect(clearUserAddedReplacements, &QAction::triggered, [this]() { connect(clearUserAddedReplacements, &QAction::triggered, [this]() {
@@ -1023,7 +1007,7 @@ void InsertVirtualMethodsDialog::initGui()
m_clearUserAddedReplacementsButton = new QToolButton(this); m_clearUserAddedReplacementsButton = new QToolButton(this);
m_clearUserAddedReplacementsButton->setDefaultAction(clearUserAddedReplacements); m_clearUserAddedReplacementsButton->setDefaultAction(clearUserAddedReplacements);
QHBoxLayout *overrideWidgetsLayout = new QHBoxLayout(this); auto overrideWidgetsLayout = new QHBoxLayout(this);
overrideWidgetsLayout->setSpacing(0); overrideWidgetsLayout->setSpacing(0);
overrideWidgetsLayout->setMargin(0); overrideWidgetsLayout->setMargin(0);
overrideWidgetsLayout->addWidget(m_overrideReplacementCheckBox); overrideWidgetsLayout->addWidget(m_overrideReplacementCheckBox);
@@ -1145,8 +1129,7 @@ void InsertVirtualMethodsDialog::setHasReimplementedFunctions(bool functions)
void InsertVirtualMethodsDialog::setHideReimplementedFunctions(bool hide) void InsertVirtualMethodsDialog::setHideReimplementedFunctions(bool hide)
{ {
InsertVirtualMethodsFilterModel *model = auto model = qobject_cast<InsertVirtualMethodsFilterModel *>(classFunctionFilterModel);
qobject_cast<InsertVirtualMethodsFilterModel *>(classFunctionFilterModel);
if (m_expansionStateNormal.isEmpty() && m_expansionStateReimp.isEmpty()) { if (m_expansionStateNormal.isEmpty() && m_expansionStateReimp.isEmpty()) {
model->setHideReimplementedFunctions(hide); model->setHideReimplementedFunctions(hide);
@@ -1172,8 +1155,7 @@ void InsertVirtualMethodsDialog::updateOverrideReplacementsComboBox()
void InsertVirtualMethodsDialog::saveExpansionState() void InsertVirtualMethodsDialog::saveExpansionState()
{ {
InsertVirtualMethodsFilterModel *model = auto model = qobject_cast<InsertVirtualMethodsFilterModel *>(classFunctionFilterModel);
qobject_cast<InsertVirtualMethodsFilterModel *>(classFunctionFilterModel);
QList<bool> &state = model->hideReimplemented() ? m_expansionStateReimp QList<bool> &state = model->hideReimplemented() ? m_expansionStateReimp
: m_expansionStateNormal; : m_expansionStateNormal;
@@ -1184,8 +1166,7 @@ void InsertVirtualMethodsDialog::saveExpansionState()
void InsertVirtualMethodsDialog::restoreExpansionState() void InsertVirtualMethodsDialog::restoreExpansionState()
{ {
InsertVirtualMethodsFilterModel *model = auto model = qobject_cast<InsertVirtualMethodsFilterModel *>(classFunctionFilterModel);
qobject_cast<InsertVirtualMethodsFilterModel *>(classFunctionFilterModel);
const QList<bool> &state = model->hideReimplemented() ? m_expansionStateReimp const QList<bool> &state = model->hideReimplemented() ? m_expansionStateReimp
: m_expansionStateNormal; : m_expansionStateNormal;

View File

@@ -36,9 +36,9 @@ class InsertVirtualMethods : public CppQuickFixFactory
{ {
Q_OBJECT Q_OBJECT
public: public:
InsertVirtualMethods(InsertVirtualMethodsDialog *dialog = 0); InsertVirtualMethods(InsertVirtualMethodsDialog *dialog = nullptr);
~InsertVirtualMethods(); ~InsertVirtualMethods() override;
void match(const CppQuickFixInterface &interface, TextEditor::QuickFixOperations &result); void match(const CppQuickFixInterface &interface, TextEditor::QuickFixOperations &result) override;
#ifdef WITH_TESTS #ifdef WITH_TESTS
static InsertVirtualMethods *createTestFactory(); static InsertVirtualMethods *createTestFactory();
#endif #endif

View File

@@ -51,7 +51,7 @@ public:
static Actions createShowInfoBarActions(const ActionCreator &actionCreator); static Actions createShowInfoBarActions(const ActionCreator &actionCreator);
public: public:
explicit MinimizableInfoBars(Core::InfoBar &infoBar, QObject *parent = 0); explicit MinimizableInfoBars(Core::InfoBar &infoBar, QObject *parent = nullptr);
// Expected call order: processHasProjectPart(), processHeaderDiagnostics() // Expected call order: processHasProjectPart(), processHeaderDiagnostics()
void processHasProjectPart(bool hasProjectPart); void processHasProjectPart(bool hasProjectPart);

View File

@@ -38,9 +38,9 @@ class CppPreProcessorDialog : public QDialog
public: public:
explicit CppPreProcessorDialog(const QString &filePath, QWidget *parent); explicit CppPreProcessorDialog(const QString &filePath, QWidget *parent);
~CppPreProcessorDialog(); ~CppPreProcessorDialog() override;
int exec(); int exec() override;
QString extraPreprocessorDirectives() const; QString extraPreprocessorDirectives() const;

View File

@@ -39,5 +39,4 @@ CppQuickFixOperation::CppQuickFixOperation(const CppQuickFixInterface &interface
: QuickFixOperation(priority), CppQuickFixInterface(interface) : QuickFixOperation(priority), CppQuickFixInterface(interface)
{} {}
CppQuickFixOperation::~CppQuickFixOperation() CppQuickFixOperation::~CppQuickFixOperation() = default;
{}

View File

@@ -39,7 +39,7 @@ class CPPEDITOR_EXPORT CppQuickFixOperation
{ {
public: public:
explicit CppQuickFixOperation(const CppQuickFixInterface &interface, int priority = -1); explicit CppQuickFixOperation(const CppQuickFixInterface &interface, int priority = -1);
~CppQuickFixOperation(); ~CppQuickFixOperation() override;
}; };
/*! /*!
@@ -60,7 +60,7 @@ class CPPEDITOR_EXPORT CppQuickFixFactory : public QObject
public: public:
CppQuickFixFactory(); CppQuickFixFactory();
~CppQuickFixFactory(); ~CppQuickFixFactory() override;
using QuickFixOperations = TextEditor::QuickFixOperations; using QuickFixOperations = TextEditor::QuickFixOperations;

View File

@@ -35,7 +35,7 @@
namespace CppTools { namespace CppTools {
class CppRefactoringFile; class CppRefactoringFile;
typedef QSharedPointer<CppRefactoringFile> CppRefactoringFilePtr; using CppRefactoringFilePtr = QSharedPointer<CppRefactoringFile>;
} }
namespace CppEditor { namespace CppEditor {

View File

@@ -173,23 +173,23 @@ inline bool isQtFuzzyComparable(const QString &typeName)
Class *isMemberFunction(const LookupContext &context, Function *function) Class *isMemberFunction(const LookupContext &context, Function *function)
{ {
QTC_ASSERT(function, return 0); QTC_ASSERT(function, return nullptr);
Scope *enclosingScope = function->enclosingScope(); Scope *enclosingScope = function->enclosingScope();
while (!(enclosingScope->isNamespace() || enclosingScope->isClass())) while (!(enclosingScope->isNamespace() || enclosingScope->isClass()))
enclosingScope = enclosingScope->enclosingScope(); enclosingScope = enclosingScope->enclosingScope();
QTC_ASSERT(enclosingScope != 0, return 0); QTC_ASSERT(enclosingScope != nullptr, return nullptr);
const Name *functionName = function->name(); const Name *functionName = function->name();
if (!functionName) if (!functionName)
return 0; return nullptr;
if (!functionName->isQualifiedNameId()) if (!functionName->isQualifiedNameId())
return 0; // trying to add a declaration for a global function return nullptr; // trying to add a declaration for a global function
const QualifiedNameId *q = functionName->asQualifiedNameId(); const QualifiedNameId *q = functionName->asQualifiedNameId();
if (!q->base()) if (!q->base())
return 0; return nullptr;
if (ClassOrNamespace *binding = context.lookupType(q->base(), enclosingScope)) { if (ClassOrNamespace *binding = context.lookupType(q->base(), enclosingScope)) {
foreach (Symbol *s, binding->symbols()) { foreach (Symbol *s, binding->symbols()) {
@@ -198,23 +198,23 @@ Class *isMemberFunction(const LookupContext &context, Function *function)
} }
} }
return 0; return nullptr;
} }
Namespace *isNamespaceFunction(const LookupContext &context, Function *function) Namespace *isNamespaceFunction(const LookupContext &context, Function *function)
{ {
QTC_ASSERT(function, return 0); QTC_ASSERT(function, return nullptr);
if (isMemberFunction(context, function)) if (isMemberFunction(context, function))
return 0; return nullptr;
Scope *enclosingScope = function->enclosingScope(); Scope *enclosingScope = function->enclosingScope();
while (!(enclosingScope->isNamespace() || enclosingScope->isClass())) while (!(enclosingScope->isNamespace() || enclosingScope->isClass()))
enclosingScope = enclosingScope->enclosingScope(); enclosingScope = enclosingScope->enclosingScope();
QTC_ASSERT(enclosingScope != 0, return 0); QTC_ASSERT(enclosingScope != nullptr, return nullptr);
const Name *functionName = function->name(); const Name *functionName = function->name();
if (!functionName) if (!functionName)
return 0; return nullptr;
// global namespace // global namespace
if (!functionName->isQualifiedNameId()) { if (!functionName->isQualifiedNameId()) {
@@ -222,12 +222,12 @@ Namespace *isNamespaceFunction(const LookupContext &context, Function *function)
if (Namespace *matchingNamespace = s->asNamespace()) if (Namespace *matchingNamespace = s->asNamespace())
return matchingNamespace; return matchingNamespace;
} }
return 0; return nullptr;
} }
const QualifiedNameId *q = functionName->asQualifiedNameId(); const QualifiedNameId *q = functionName->asQualifiedNameId();
if (!q->base()) if (!q->base())
return 0; return nullptr;
if (ClassOrNamespace *binding = context.lookupType(q->base(), enclosingScope)) { if (ClassOrNamespace *binding = context.lookupType(q->base(), enclosingScope)) {
foreach (Symbol *s, binding->symbols()) { foreach (Symbol *s, binding->symbols()) {
@@ -236,7 +236,7 @@ Namespace *isNamespaceFunction(const LookupContext &context, Function *function)
} }
} }
return 0; return nullptr;
} }
// Given include is e.g. "afile.h" or <afile.h> (quotes/angle brackets included!). // Given include is e.g. "afile.h" or <afile.h> (quotes/angle brackets included!).
@@ -308,10 +308,12 @@ namespace {
class InverseLogicalComparisonOp: public CppQuickFixOperation class InverseLogicalComparisonOp: public CppQuickFixOperation
{ {
public: public:
InverseLogicalComparisonOp(const CppQuickFixInterface &interface, int priority, InverseLogicalComparisonOp(const CppQuickFixInterface &interface,
BinaryExpressionAST *binary, Kind invertToken) int priority,
BinaryExpressionAST *binary,
Kind invertToken)
: CppQuickFixOperation(interface, priority) : CppQuickFixOperation(interface, priority)
, binary(binary), nested(0), negation(0) , binary(binary)
{ {
Token tok; Token tok;
tok.f.kind = invertToken; tok.f.kind = invertToken;
@@ -324,19 +326,17 @@ public:
// check for ! before parentheses // check for ! before parentheses
if (nested && priority - 2 >= 0) { if (nested && priority - 2 >= 0) {
negation = interface.path()[priority - 2]->asUnaryExpression(); negation = interface.path()[priority - 2]->asUnaryExpression();
if (negation if (negation && !interface.currentFile()->tokenAt(negation->unary_op_token).is(T_EXCLAIM))
&& !interface.currentFile()->tokenAt(negation->unary_op_token).is(T_EXCLAIM)) { negation = nullptr;
negation = 0;
}
} }
} }
QString description() const QString description() const override
{ {
return QApplication::translate("CppTools::QuickFix", "Rewrite Using %1").arg(replacement); return QApplication::translate("CppTools::QuickFix", "Rewrite Using %1").arg(replacement);
} }
void perform() void perform() override
{ {
CppRefactoringChanges refactoring(snapshot()); CppRefactoringChanges refactoring(snapshot());
CppRefactoringFilePtr currentFile = refactoring.file(fileName()); CppRefactoringFilePtr currentFile = refactoring.file(fileName());
@@ -357,9 +357,9 @@ public:
} }
private: private:
BinaryExpressionAST *binary; BinaryExpressionAST *binary = nullptr;
NestedExpressionAST *nested; NestedExpressionAST *nested = nullptr;
UnaryExpressionAST *negation; UnaryExpressionAST *negation = nullptr;
QString replacement; QString replacement;
}; };
@@ -420,7 +420,7 @@ public:
setPriority(priority); setPriority(priority);
} }
QString description() const QString description() const override
{ {
if (replacement.isEmpty()) if (replacement.isEmpty())
return QApplication::translate("CppTools::QuickFix", "Swap Operands"); return QApplication::translate("CppTools::QuickFix", "Swap Operands");
@@ -428,7 +428,7 @@ public:
return QApplication::translate("CppTools::QuickFix", "Rewrite Using %1").arg(replacement); return QApplication::translate("CppTools::QuickFix", "Rewrite Using %1").arg(replacement);
} }
void perform() void perform() override
{ {
CppRefactoringChanges refactoring(snapshot()); CppRefactoringChanges refactoring(snapshot());
CppRefactoringFilePtr currentFile = refactoring.file(fileName()); CppRefactoringFilePtr currentFile = refactoring.file(fileName());
@@ -515,7 +515,7 @@ public:
pattern = mk->BinaryExpression(left, right); pattern = mk->BinaryExpression(left, right);
} }
void perform() void perform() override
{ {
CppRefactoringChanges refactoring(snapshot()); CppRefactoringChanges refactoring(snapshot());
CppRefactoringFilePtr currentFile = refactoring.file(fileName()); CppRefactoringFilePtr currentFile = refactoring.file(fileName());
@@ -539,7 +539,7 @@ public:
void RewriteLogicalAnd::match(const CppQuickFixInterface &interface, QuickFixOperations &result) void RewriteLogicalAnd::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{ {
BinaryExpressionAST *expression = 0; BinaryExpressionAST *expression = nullptr;
const QList<AST *> &path = interface.path(); const QList<AST *> &path = interface.path();
CppRefactoringFilePtr file = interface.currentFile(); CppRefactoringFilePtr file = interface.currentFile();
@@ -582,10 +582,10 @@ static bool checkDeclarationForSplit(SimpleDeclarationAST *declaration)
for (SpecifierListAST *it = declaration->decl_specifier_list; it; it = it->next) { for (SpecifierListAST *it = declaration->decl_specifier_list; it; it = it->next) {
SpecifierAST *specifier = it->value; SpecifierAST *specifier = it->value;
if (specifier->asEnumSpecifier() != 0) if (specifier->asEnumSpecifier() != nullptr)
return false; return false;
else if (specifier->asClassSpecifier() != 0) else if (specifier->asClassSpecifier() != nullptr)
return false; return false;
} }
@@ -612,7 +612,7 @@ public:
"Split Declaration")); "Split Declaration"));
} }
void perform() void perform() override
{ {
CppRefactoringChanges refactoring(snapshot()); CppRefactoringChanges refactoring(snapshot());
CppRefactoringFilePtr currentFile = refactoring.file(fileName()); CppRefactoringFilePtr currentFile = refactoring.file(fileName());
@@ -655,7 +655,7 @@ private:
void SplitSimpleDeclaration::match(const CppQuickFixInterface &interface, void SplitSimpleDeclaration::match(const CppQuickFixInterface &interface,
QuickFixOperations &result) QuickFixOperations &result)
{ {
CoreDeclaratorAST *core_declarator = 0; CoreDeclaratorAST *core_declarator = nullptr;
const QList<AST *> &path = interface.path(); const QList<AST *> &path = interface.path();
CppRefactoringFilePtr file = interface.currentFile(); CppRefactoringFilePtr file = interface.currentFile();
const int cursorPosition = file->cursor().selectionStart(); const int cursorPosition = file->cursor().selectionStart();
@@ -702,7 +702,7 @@ public:
setDescription(QApplication::translate("CppTools::QuickFix", "Add Curly Braces")); setDescription(QApplication::translate("CppTools::QuickFix", "Add Curly Braces"));
} }
void perform() void perform() override
{ {
CppRefactoringChanges refactoring(snapshot()); CppRefactoringChanges refactoring(snapshot());
CppRefactoringFilePtr currentFile = refactoring.file(fileName()); CppRefactoringFilePtr currentFile = refactoring.file(fileName());
@@ -775,7 +775,7 @@ public:
pattern = mk.IfStatement(condition); pattern = mk.IfStatement(condition);
} }
void perform() void perform() override
{ {
CppRefactoringChanges refactoring(snapshot()); CppRefactoringChanges refactoring(snapshot());
CppRefactoringFilePtr currentFile = refactoring.file(fileName()); CppRefactoringFilePtr currentFile = refactoring.file(fileName());
@@ -806,7 +806,7 @@ void MoveDeclarationOutOfIf::match(const CppQuickFixInterface &interface,
QuickFixOperations &result) QuickFixOperations &result)
{ {
const QList<AST *> &path = interface.path(); const QList<AST *> &path = interface.path();
typedef QSharedPointer<MoveDeclarationOutOfIfOp> Ptr; using Ptr = QSharedPointer<MoveDeclarationOutOfIfOp>;
Ptr op(new MoveDeclarationOutOfIfOp(interface)); Ptr op(new MoveDeclarationOutOfIfOp(interface));
int index = path.size() - 1; int index = path.size() - 1;
@@ -849,7 +849,7 @@ public:
pattern = mk.WhileStatement(condition); pattern = mk.WhileStatement(condition);
} }
void perform() void perform() override
{ {
CppRefactoringChanges refactoring(snapshot()); CppRefactoringChanges refactoring(snapshot());
CppRefactoringFilePtr currentFile = refactoring.file(fileName()); CppRefactoringFilePtr currentFile = refactoring.file(fileName());
@@ -928,7 +928,7 @@ public:
"Split if Statement")); "Split if Statement"));
} }
void perform() void perform() override
{ {
CppRefactoringChanges refactoring(snapshot()); CppRefactoringChanges refactoring(snapshot());
CppRefactoringFilePtr currentFile = refactoring.file(fileName()); CppRefactoringFilePtr currentFile = refactoring.file(fileName());
@@ -997,7 +997,7 @@ private:
void SplitIfStatement::match(const CppQuickFixInterface &interface, QuickFixOperations &result) void SplitIfStatement::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{ {
IfStatementAST *pattern = 0; IfStatementAST *pattern = nullptr;
const QList<AST *> &path = interface.path(); const QList<AST *> &path = interface.path();
int index = path.size() - 1; int index = path.size() - 1;
@@ -1118,10 +1118,10 @@ static ExpressionAST *analyzeStringLiteral(const QList<AST *> &path,
if (enclosingFunction) if (enclosingFunction)
enclosingFunction->clear(); enclosingFunction->clear();
if (enclosingFunctionCall) if (enclosingFunctionCall)
*enclosingFunctionCall = 0; *enclosingFunctionCall = nullptr;
if (path.isEmpty()) if (path.isEmpty())
return 0; return nullptr;
ExpressionAST *literal = path.last()->asExpression(); ExpressionAST *literal = path.last()->asExpression();
if (literal) { if (literal) {
@@ -1167,7 +1167,7 @@ public:
setDescription(description); setDescription(description);
} }
void perform() void perform() override
{ {
CppRefactoringChanges refactoring(snapshot()); CppRefactoringChanges refactoring(snapshot());
CppRefactoringFilePtr currentFile = refactoring.file(fileName()); CppRefactoringFilePtr currentFile = refactoring.file(fileName());
@@ -1371,7 +1371,7 @@ public:
"Convert to Objective-C String Literal")); "Convert to Objective-C String Literal"));
} }
void perform() void perform() override
{ {
CppRefactoringChanges refactoring(snapshot()); CppRefactoringChanges refactoring(snapshot());
CppRefactoringFilePtr currentFile = refactoring.file(fileName()); CppRefactoringFilePtr currentFile = refactoring.file(fileName());
@@ -1414,7 +1414,7 @@ void ConvertCStringToNSString::match(const CppQuickFixInterface &interface,
if (!literal || type != TypeString) if (!literal || type != TypeString)
return; return;
if (!isQtStringLiteral(enclosingFunction)) if (!isQtStringLiteral(enclosingFunction))
qlatin1Call = 0; qlatin1Call = nullptr;
result << new ConvertCStringToNSStringOp(interface, path.size() - 1, literal->asStringLiteral(), result << new ConvertCStringToNSStringOp(interface, path.size() - 1, literal->asStringLiteral(),
qlatin1Call); qlatin1Call);
@@ -1433,7 +1433,7 @@ public:
, replacement(replacement) , replacement(replacement)
{} {}
void perform() void perform() override
{ {
CppRefactoringChanges refactoring(snapshot()); CppRefactoringChanges refactoring(snapshot());
CppRefactoringFilePtr currentFile = refactoring.file(fileName()); CppRefactoringFilePtr currentFile = refactoring.file(fileName());
@@ -1595,7 +1595,7 @@ public:
setDescription(QApplication::translate("CppTools::QuickFix", "Add Local Declaration")); setDescription(QApplication::translate("CppTools::QuickFix", "Add Local Declaration"));
} }
void perform() void perform() override
{ {
CppRefactoringChanges refactoring(snapshot()); CppRefactoringChanges refactoring(snapshot());
CppRefactoringFilePtr currentFile = refactoring.file(fileName()); CppRefactoringFilePtr currentFile = refactoring.file(fileName());
@@ -1652,10 +1652,10 @@ void AddLocalDeclaration::match(const CppQuickFixInterface &interface, QuickFixO
&& file->tokenAt(binary->binary_op_token).is(T_EQUAL)) { && file->tokenAt(binary->binary_op_token).is(T_EQUAL)) {
IdExpressionAST *idExpr = binary->left_expression->asIdExpression(); IdExpressionAST *idExpr = binary->left_expression->asIdExpression();
if (interface.isCursorOn(binary->left_expression) && idExpr if (interface.isCursorOn(binary->left_expression) && idExpr
&& idExpr->name->asSimpleName() != 0) { && idExpr->name->asSimpleName() != nullptr) {
SimpleNameAST *nameAST = idExpr->name->asSimpleName(); SimpleNameAST *nameAST = idExpr->name->asSimpleName();
const QList<LookupItem> results = interface.context().lookup(nameAST->name, file->scopeAt(nameAST->firstToken())); const QList<LookupItem> results = interface.context().lookup(nameAST->name, file->scopeAt(nameAST->firstToken()));
Declaration *decl = 0; Declaration *decl = nullptr;
foreach (const LookupItem &r, results) { foreach (const LookupItem &r, results) {
if (!r.declaration()) if (!r.declaration())
continue; continue;
@@ -1689,7 +1689,7 @@ public:
setDescription(QApplication::translate("CppTools::QuickFix", "Convert to Camel Case")); setDescription(QApplication::translate("CppTools::QuickFix", "Convert to Camel Case"));
} }
void perform() void perform() override
{ {
CppRefactoringChanges refactoring(snapshot()); CppRefactoringChanges refactoring(snapshot());
CppRefactoringFilePtr currentFile = refactoring.file(fileName()); CppRefactoringFilePtr currentFile = refactoring.file(fileName());
@@ -1727,7 +1727,7 @@ void ConvertToCamelCase::match(const CppQuickFixInterface &interface, QuickFixOp
return; return;
AST * const ast = path.last(); AST * const ast = path.last();
const Name *name = 0; const Name *name = nullptr;
if (const NameAST * const nameAst = ast->asName()) { if (const NameAST * const nameAst = ast->asName()) {
if (nameAst->name && nameAst->name->asNameId()) if (nameAst->name && nameAst->name->asNameId())
name = nameAst->name; name = nameAst->name;
@@ -1832,9 +1832,9 @@ ProjectExplorer::HeaderPaths relevantHeaderPaths(const QString &filePath)
NameAST *nameUnderCursor(const QList<AST *> &path) NameAST *nameUnderCursor(const QList<AST *> &path)
{ {
if (path.isEmpty()) if (path.isEmpty())
return 0; return nullptr;
NameAST *nameAst = 0; NameAST *nameAst = nullptr;
for (int i = path.size() - 1; i >= 0; --i) { for (int i = path.size() - 1; i >= 0; --i) {
AST * const ast = path.at(i); AST * const ast = path.at(i);
if (SimpleNameAST *simpleName = ast->asSimpleName()) { if (SimpleNameAST *simpleName = ast->asSimpleName()) {
@@ -2037,7 +2037,7 @@ public:
setDescription(targetString); setDescription(targetString);
} }
void perform() void perform() override
{ {
CppRefactoringChanges refactoring(snapshot()); CppRefactoringChanges refactoring(snapshot());
CppRefactoringFilePtr currentFile = refactoring.file(fileName()); CppRefactoringFilePtr currentFile = refactoring.file(fileName());
@@ -2063,7 +2063,7 @@ void RearrangeParamDeclarationList::match(const CppQuickFixInterface &interface,
{ {
const QList<AST *> path = interface.path(); const QList<AST *> path = interface.path();
ParameterDeclarationAST *paramDecl = 0; ParameterDeclarationAST *paramDecl = nullptr;
int index = path.size() - 1; int index = path.size() - 1;
for (; index != -1; --index) { for (; index != -1; --index) {
paramDecl = path.at(index)->asParameterDeclaration(); paramDecl = path.at(index)->asParameterDeclaration();
@@ -2078,7 +2078,7 @@ void RearrangeParamDeclarationList::match(const CppQuickFixInterface &interface,
QTC_ASSERT(paramDeclClause && paramDeclClause->parameter_declaration_list, return); QTC_ASSERT(paramDeclClause && paramDeclClause->parameter_declaration_list, return);
ParameterDeclarationListAST *paramListNode = paramDeclClause->parameter_declaration_list; ParameterDeclarationListAST *paramListNode = paramDeclClause->parameter_declaration_list;
ParameterDeclarationListAST *prevParamListNode = 0; ParameterDeclarationListAST *prevParamListNode = nullptr;
while (paramListNode) { while (paramListNode) {
if (paramDecl == paramListNode->value) if (paramDecl == paramListNode->value)
break; break;
@@ -2117,7 +2117,7 @@ public:
setDescription(description); setDescription(description);
} }
void perform() void perform() override
{ {
CppRefactoringChanges refactoring(snapshot()); CppRefactoringChanges refactoring(snapshot());
CppRefactoringFilePtr currentFile = refactoring.file(fileName()); CppRefactoringFilePtr currentFile = refactoring.file(fileName());
@@ -2135,15 +2135,6 @@ private:
class ReformatPointerDeclarationASTPathResultsFilter class ReformatPointerDeclarationASTPathResultsFilter
{ {
public: public:
ReformatPointerDeclarationASTPathResultsFilter()
: m_hasSimpleDeclaration(false)
, m_hasFunctionDefinition(false)
, m_hasParameterDeclaration(false)
, m_hasIfStatement(false)
, m_hasWhileStatement(false)
, m_hasForStatement(false)
, m_hasForeachStatement(false) {}
QList<AST*> filter(const QList<AST*> &astPathList) QList<AST*> filter(const QList<AST*> &astPathList)
{ {
QList<AST*> filtered; QList<AST*> filtered;
@@ -2179,13 +2170,13 @@ public:
} }
private: private:
bool m_hasSimpleDeclaration; bool m_hasSimpleDeclaration = false;
bool m_hasFunctionDefinition; bool m_hasFunctionDefinition = false;
bool m_hasParameterDeclaration; bool m_hasParameterDeclaration = false;
bool m_hasIfStatement; bool m_hasIfStatement = false;
bool m_hasWhileStatement; bool m_hasWhileStatement = false;
bool m_hasForStatement; bool m_hasForStatement = false;
bool m_hasForeachStatement; bool m_hasForeachStatement = false;
}; };
} // anonymous namespace } // anonymous namespace
@@ -2248,7 +2239,7 @@ public:
return values; return values;
} }
bool preVisit(AST *ast) { bool preVisit(AST *ast) override {
if (CaseStatementAST *cs = ast->asCaseStatement()) { if (CaseStatementAST *cs = ast->asCaseStatement()) {
foundCaseStatementLevel = true; foundCaseStatementLevel = true;
if (ExpressionAST *csExpression = cs->expression) { if (ExpressionAST *csExpression = cs->expression) {
@@ -2288,7 +2279,7 @@ public:
"Complete Switch Statement")); "Complete Switch Statement"));
} }
void perform() void perform() override
{ {
CppRefactoringChanges refactoring(snapshot()); CppRefactoringChanges refactoring(snapshot());
CppRefactoringFilePtr currentFile = refactoring.file(fileName()); CppRefactoringFilePtr currentFile = refactoring.file(fileName());
@@ -2335,7 +2326,7 @@ static Enum *findEnum(const QList<LookupItem> &results, const LookupContext &ctx
} }
} }
return 0; return nullptr;
} }
Enum *conditionEnum(const CppQuickFixInterface &interface, SwitchStatementAST *statement) Enum *conditionEnum(const CppQuickFixInterface &interface, SwitchStatementAST *statement)
@@ -2418,7 +2409,7 @@ public:
.arg(InsertionPointLocator::accessSpecToString(xsSpec))); .arg(InsertionPointLocator::accessSpecToString(xsSpec)));
} }
void perform() void perform() override
{ {
CppRefactoringChanges refactoring(snapshot()); CppRefactoringChanges refactoring(snapshot());
@@ -2478,7 +2469,7 @@ void InsertDeclFromDef::match(const CppQuickFixInterface &interface, QuickFixOpe
const QList<AST *> &path = interface.path(); const QList<AST *> &path = interface.path();
CppRefactoringFilePtr file = interface.currentFile(); CppRefactoringFilePtr file = interface.currentFile();
FunctionDefinitionAST *funDef = 0; FunctionDefinitionAST *funDef = nullptr;
int idx = 0; int idx = 0;
for (; idx < path.size(); ++idx) { for (; idx < path.size(); ++idx) {
AST *node = path.at(idx); AST *node = path.at(idx);
@@ -2593,7 +2584,7 @@ public:
} }
} }
void perform() void perform() override
{ {
CppRefactoringChanges refactoring(snapshot()); CppRefactoringChanges refactoring(snapshot());
if (!m_loc.isValid()) if (!m_loc.isValid())
@@ -2714,7 +2705,7 @@ void InsertDefFromDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
// Insert Position: Implementation File // Insert Position: Implementation File
DeclaratorAST *declAST = simpleDecl->declarator_list->value; DeclaratorAST *declAST = simpleDecl->declarator_list->value;
InsertDefOperation *op = 0; InsertDefOperation *op = nullptr;
ProjectFile::Kind kind = ProjectFile::classify(interface.fileName()); ProjectFile::Kind kind = ProjectFile::classify(interface.fileName());
const bool isHeaderFile = ProjectFile::isHeader(kind); const bool isHeaderFile = ProjectFile::isHeader(kind);
if (isHeaderFile) { if (isHeaderFile) {
@@ -2752,7 +2743,7 @@ void InsertDefFromDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
} }
// Determine if we are dealing with a free function // Determine if we are dealing with a free function
const bool isFreeFunction = func->enclosingClass() == 0; const bool isFreeFunction = func->enclosingClass() == nullptr;
// Insert Position: Outside Class // Insert Position: Outside Class
if (!isFreeFunction) { if (!isFreeFunction) {
@@ -2817,15 +2808,6 @@ public:
GenerateGetterSetterOperation(const CppQuickFixInterface &interface) GenerateGetterSetterOperation(const CppQuickFixInterface &interface)
: CppQuickFixOperation(interface) : CppQuickFixOperation(interface)
, m_type(InvalidType)
, m_variableName(0)
, m_declaratorId(0)
, m_declarator(0)
, m_variableDecl(0)
, m_classSpecifier(0)
, m_classDecl(0)
, m_symbol(0)
, m_offerQuickFix(true)
{ {
const QList<AST *> &path = interface.path(); const QList<AST *> &path = interface.path();
// We expect something like // We expect something like
@@ -3037,7 +3019,7 @@ public:
&& m_offerQuickFix; && m_offerQuickFix;
} }
void perform() void perform() override
{ {
CppRefactoringChanges refactoring(snapshot()); CppRefactoringChanges refactoring(snapshot());
CppRefactoringFilePtr currentFile = refactoring.file(fileName()); CppRefactoringFilePtr currentFile = refactoring.file(fileName());
@@ -3175,20 +3157,20 @@ public:
currentFile->apply(); currentFile->apply();
} }
OperationType m_type; OperationType m_type = InvalidType;
SimpleNameAST *m_variableName; SimpleNameAST *m_variableName = nullptr;
DeclaratorIdAST *m_declaratorId; DeclaratorIdAST *m_declaratorId = nullptr;
DeclaratorAST *m_declarator; DeclaratorAST *m_declarator = nullptr;
SimpleDeclarationAST *m_variableDecl; SimpleDeclarationAST *m_variableDecl = nullptr;
ClassSpecifierAST *m_classSpecifier; ClassSpecifierAST *m_classSpecifier = nullptr;
SimpleDeclarationAST *m_classDecl; SimpleDeclarationAST *m_classDecl = nullptr;
Symbol *m_symbol; Symbol *m_symbol = nullptr;
QString m_baseName; QString m_baseName;
QString m_getterName; QString m_getterName;
QString m_setterName; QString m_setterName;
QString m_variableString; QString m_variableString;
bool m_offerQuickFix; bool m_offerQuickFix = true;
}; };
} // anonymous namespace } // anonymous namespace
@@ -3196,7 +3178,7 @@ public:
void GenerateGetterSetter::match(const CppQuickFixInterface &interface, void GenerateGetterSetter::match(const CppQuickFixInterface &interface,
QuickFixOperations &result) QuickFixOperations &result)
{ {
GenerateGetterSetterOperation *op = new GenerateGetterSetterOperation(interface); auto op = new GenerateGetterSetterOperation(interface);
if (op->m_type != GenerateGetterSetterOperation::InvalidType) { if (op->m_type != GenerateGetterSetterOperation::InvalidType) {
result << op; result << op;
if (op->m_type == GenerateGetterSetterOperation::GetterSetterType) { if (op->m_type == GenerateGetterSetterOperation::GetterSetterType) {
@@ -3215,9 +3197,6 @@ namespace {
class ExtractFunctionOptions class ExtractFunctionOptions
{ {
public: public:
ExtractFunctionOptions() : access(InsertionPointLocator::Public)
{}
static bool isValidFunctionName(const QString &name) static bool isValidFunctionName(const QString &name)
{ {
return !name.isEmpty() && isValidIdentifier(name); return !name.isEmpty() && isValidIdentifier(name);
@@ -3229,7 +3208,7 @@ public:
} }
QString funcName; QString funcName;
InsertionPointLocator::AccessSpec access; InsertionPointLocator::AccessSpec access = InsertionPointLocator::Public;
}; };
class ExtractFunctionOperation : public CppQuickFixOperation class ExtractFunctionOperation : public CppQuickFixOperation
@@ -3254,7 +3233,7 @@ public:
setDescription(QCoreApplication::translate("QuickFix::ExtractFunction", "Extract Function")); setDescription(QCoreApplication::translate("QuickFix::ExtractFunction", "Extract Function"));
} }
void perform() void perform() override
{ {
QTC_ASSERT(!m_funcReturn || !m_relevantDecls.isEmpty(), return); QTC_ASSERT(!m_funcReturn || !m_relevantDecls.isEmpty(), return);
CppRefactoringChanges refactoring(snapshot()); CppRefactoringChanges refactoring(snapshot());
@@ -3524,7 +3503,7 @@ public:
return !m_failed; return !m_failed;
} }
bool preVisit(AST *) bool preVisit(AST *) override
{ {
if (m_done) if (m_done)
return false; return false;
@@ -3553,13 +3532,13 @@ public:
accept(stmt); accept(stmt);
} }
bool visit(CaseStatementAST *stmt) bool visit(CaseStatementAST *stmt) override
{ {
statement(stmt->statement); statement(stmt->statement);
return false; return false;
} }
bool visit(CompoundStatementAST *stmt) bool visit(CompoundStatementAST *stmt) override
{ {
for (StatementListAST *it = stmt->statement_list; it; it = it->next) { for (StatementListAST *it = stmt->statement_list; it; it = it->next) {
statement(it->value); statement(it->value);
@@ -3569,25 +3548,25 @@ public:
return false; return false;
} }
bool visit(DoStatementAST *stmt) bool visit(DoStatementAST *stmt) override
{ {
statement(stmt->statement); statement(stmt->statement);
return false; return false;
} }
bool visit(ForeachStatementAST *stmt) bool visit(ForeachStatementAST *stmt) override
{ {
statement(stmt->statement); statement(stmt->statement);
return false; return false;
} }
bool visit(RangeBasedForStatementAST *stmt) bool visit(RangeBasedForStatementAST *stmt) override
{ {
statement(stmt->statement); statement(stmt->statement);
return false; return false;
} }
bool visit(ForStatementAST *stmt) bool visit(ForStatementAST *stmt) override
{ {
statement(stmt->initializer); statement(stmt->initializer);
if (!m_done) if (!m_done)
@@ -3595,7 +3574,7 @@ public:
return false; return false;
} }
bool visit(IfStatementAST *stmt) bool visit(IfStatementAST *stmt) override
{ {
statement(stmt->statement); statement(stmt->statement);
if (!m_done) if (!m_done)
@@ -3603,7 +3582,7 @@ public:
return false; return false;
} }
bool visit(TryBlockStatementAST *stmt) bool visit(TryBlockStatementAST *stmt) override
{ {
statement(stmt->statement); statement(stmt->statement);
for (CatchClauseListAST *it = stmt->catch_clause_list; it; it = it->next) { for (CatchClauseListAST *it = stmt->catch_clause_list; it; it = it->next) {
@@ -3614,13 +3593,13 @@ public:
return false; return false;
} }
bool visit(WhileStatementAST *stmt) bool visit(WhileStatementAST *stmt) override
{ {
statement(stmt->statement); statement(stmt->statement);
return false; return false;
} }
bool visit(DeclarationStatementAST *declStmt) bool visit(DeclarationStatementAST *declStmt) override
{ {
// We need to collect the declarations we see before the extraction or even inside it. // We need to collect the declarations we see before the extraction or even inside it.
// They might need to be used as either a parameter or return value. Actually, we could // They might need to be used as either a parameter or return value. Actually, we could
@@ -3649,7 +3628,7 @@ public:
return false; return false;
} }
bool visit(ReturnStatementAST *) bool visit(ReturnStatementAST *) override
{ {
if (m_extractionStart) { if (m_extractionStart) {
m_done = true; m_done = true;
@@ -3686,7 +3665,7 @@ void ExtractFunction::match(const CppQuickFixInterface &interface, QuickFixOpera
return; return;
const QList<AST *> &path = interface.path(); const QList<AST *> &path = interface.path();
FunctionDefinitionAST *refFuncDef = 0; // The "reference" function, which we will extract from. FunctionDefinitionAST *refFuncDef = nullptr; // The "reference" function, which we will extract from.
for (int i = path.size() - 1; i >= 0; --i) { for (int i = path.size() - 1; i >= 0; --i) {
refFuncDef = path.at(i)->asFunctionDefinition(); refFuncDef = path.at(i)->asFunctionDefinition();
if (refFuncDef) if (refFuncDef)
@@ -3751,7 +3730,7 @@ void ExtractFunction::match(const CppQuickFixInterface &interface, QuickFixOpera
} }
// Identify what would be parameters for the new function and its return value, if any. // Identify what would be parameters for the new function and its return value, if any.
Symbol *funcReturn = 0; Symbol *funcReturn = nullptr;
QList<QPair<QString, QString> > relevantDecls; QList<QPair<QString, QString> > relevantDecls;
SemanticInfo::LocalUseIterator it(interface.semanticInfo().localUses); SemanticInfo::LocalUseIterator it(interface.semanticInfo().localUses);
while (it.hasNext()) { while (it.hasNext()) {
@@ -3853,7 +3832,7 @@ public:
} }
private: private:
bool visit(T *ast) bool visit(T *ast) override
{ {
if (ast != m_literal if (ast != m_literal
&& strcmp(m_file->tokenAt(ast->firstToken()).spell(), m_literalTokenText) != 0) { && strcmp(m_file->tokenAt(ast->firstToken()).spell(), m_literalTokenText) != 0) {
@@ -3887,11 +3866,7 @@ public:
struct FoundDeclaration struct FoundDeclaration
{ {
FoundDeclaration() FunctionDeclaratorAST *ast = nullptr;
: ast(0)
{}
FunctionDeclaratorAST *ast;
CppRefactoringFilePtr file; CppRefactoringFilePtr file;
}; };
@@ -3963,7 +3938,7 @@ public:
return result; return result;
} }
void perform() void perform() override
{ {
FunctionDeclaratorAST *functionDeclaratorOfDefinition FunctionDeclaratorAST *functionDeclaratorOfDefinition
= functionDeclarator(m_functionDefinition); = functionDeclarator(m_functionDefinition);
@@ -4043,7 +4018,7 @@ private:
if (functionDeclaratorAST) if (functionDeclaratorAST)
return functionDeclaratorAST; return functionDeclaratorAST;
} }
return 0; return nullptr;
} }
FunctionDeclaratorAST *functionDeclarator(DeclaratorAST *ast) const FunctionDeclaratorAST *functionDeclarator(DeclaratorAST *ast) const
@@ -4053,7 +4028,7 @@ private:
if (funcdecl) if (funcdecl)
return funcdecl; return funcdecl;
} }
return 0; return nullptr;
} }
FunctionDeclaratorAST *functionDeclarator(FunctionDefinitionAST *ast) const FunctionDeclaratorAST *functionDeclarator(FunctionDefinitionAST *ast) const
@@ -4197,7 +4172,7 @@ private:
{ {
ExpressionListParenAST *exprlist = newExprAST->new_initializer ExpressionListParenAST *exprlist = newExprAST->new_initializer
? newExprAST->new_initializer->asExpressionListParen() ? newExprAST->new_initializer->asExpressionListParen()
: 0; : nullptr;
if (exprlist && exprlist->expression_list) { if (exprlist && exprlist->expression_list) {
// remove 'new' keyword and type before initializer // remove 'new' keyword and type before initializer
@@ -4403,8 +4378,8 @@ void ConvertFromAndToPointer::match(const CppQuickFixInterface &interface,
SimpleNameAST *identifier = path.last()->asSimpleName(); SimpleNameAST *identifier = path.last()->asSimpleName();
if (!identifier) if (!identifier)
return; return;
SimpleDeclarationAST *simpleDeclaration = 0; SimpleDeclarationAST *simpleDeclaration = nullptr;
DeclaratorAST *declarator = 0; DeclaratorAST *declarator = nullptr;
bool isFunctionLocal = false; bool isFunctionLocal = false;
bool isClassLocal = false; bool isClassLocal = false;
ConvertFromAndToPointerOp::Mode mode = ConvertFromAndToPointerOp::FromVariable; ConvertFromAndToPointerOp::Mode mode = ConvertFromAndToPointerOp::FromVariable;
@@ -4426,7 +4401,7 @@ void ConvertFromAndToPointer::match(const CppQuickFixInterface &interface,
if (!isFunctionLocal || !simpleDeclaration || !declarator) if (!isFunctionLocal || !simpleDeclaration || !declarator)
return; return;
Symbol *symbol = 0; Symbol *symbol = nullptr;
for (List<Symbol *> *lst = simpleDeclaration->symbols; lst; lst = lst->next) { for (List<Symbol *> *lst = simpleDeclaration->symbols; lst; lst = lst->next) {
if (lst->value->name() == identifier->name) { if (lst->value->name() == identifier->name) {
symbol = lst->value; symbol = lst->value;
@@ -4499,7 +4474,7 @@ public:
setDescription(CppQuickFixFactory::tr("Generate Missing Q_PROPERTY Members")); setDescription(CppQuickFixFactory::tr("Generate Missing Q_PROPERTY Members"));
} }
void perform() void perform() override
{ {
CppRefactoringChanges refactoring(snapshot()); CppRefactoringChanges refactoring(snapshot());
CppRefactoringFilePtr file = refactoring.file(fileName()); CppRefactoringFilePtr file = refactoring.file(fileName());
@@ -4601,7 +4576,7 @@ void InsertQtPropertyMembers::match(const CppQuickFixInterface &interface,
if (!qtPropertyDeclaration || !qtPropertyDeclaration->type_id) if (!qtPropertyDeclaration || !qtPropertyDeclaration->type_id)
return; return;
ClassSpecifierAST *klass = 0; ClassSpecifierAST *klass = nullptr;
for (int i = path.size() - 2; i >= 0; --i) { for (int i = path.size() - 2; i >= 0; --i) {
klass = path.at(i)->asClassSpecifier(); klass = path.at(i)->asClassSpecifier();
if (klass) if (klass)
@@ -4673,7 +4648,7 @@ public:
, m_link(link) , m_link(link)
{} {}
void perform() void perform() override
{ {
if (editor()->declDefLink() == m_link) if (editor()->declDefLink() == m_link)
editor()->applyDeclDefLinkChanges(/*don't jump*/false); editor()->applyDeclDefLinkChanges(/*don't jump*/false);
@@ -4840,7 +4815,7 @@ public:
} }
} }
void perform() void perform() override
{ {
MoveFuncDefRefactoringHelper helper(this, m_type, m_headerFileName, m_cppFileName); MoveFuncDefRefactoringHelper helper(this, m_type, m_headerFileName, m_cppFileName);
helper.performMove(m_funcDef); helper.performMove(m_funcDef);
@@ -4859,8 +4834,8 @@ private:
void MoveFuncDefOutside::match(const CppQuickFixInterface &interface, QuickFixOperations &result) void MoveFuncDefOutside::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{ {
const QList<AST *> &path = interface.path(); const QList<AST *> &path = interface.path();
SimpleDeclarationAST *classAST = 0; SimpleDeclarationAST *classAST = nullptr;
FunctionDefinitionAST *funcAST = 0; FunctionDefinitionAST *funcAST = nullptr;
bool moveOutsideMemberDefinition = false; bool moveOutsideMemberDefinition = false;
const int pathSize = path.size(); const int pathSize = path.size();
@@ -4883,7 +4858,7 @@ void MoveFuncDefOutside::match(const CppQuickFixInterface &interface, QuickFixOp
break; break;
} }
} }
funcAST = 0; funcAST = nullptr;
} }
} }
@@ -4933,7 +4908,7 @@ public:
} }
} }
void perform() void perform() override
{ {
MoveFuncDefRefactoringHelper helper(this, m_type, m_headerFileName, m_cppFileName); MoveFuncDefRefactoringHelper helper(this, m_type, m_headerFileName, m_cppFileName);
for (DeclarationListAST *it = m_classDef->member_specifier_list; it; it = it->next) { for (DeclarationListAST *it = m_classDef->member_specifier_list; it; it = it->next) {
@@ -5024,7 +4999,7 @@ public:
} }
} }
void perform() void perform() override
{ {
CppRefactoringChanges refactoring(snapshot()); CppRefactoringChanges refactoring(snapshot());
CppRefactoringFilePtr fromFile = refactoring.file(m_fromFileName); CppRefactoringFilePtr fromFile = refactoring.file(m_fromFileName);
@@ -5065,8 +5040,8 @@ private:
void MoveFuncDefToDecl::match(const CppQuickFixInterface &interface, QuickFixOperations &result) void MoveFuncDefToDecl::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{ {
const QList<AST *> &path = interface.path(); const QList<AST *> &path = interface.path();
AST *completeDefAST = 0; AST *completeDefAST = nullptr;
FunctionDefinitionAST *funcAST = 0; FunctionDefinitionAST *funcAST = nullptr;
const int pathSize = path.size(); const int pathSize = path.size();
for (int idx = 1; idx < pathSize; ++idx) { for (int idx = 1; idx < pathSize; ++idx) {
@@ -5082,7 +5057,7 @@ void MoveFuncDefToDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
completeDefAST = enclosingAST->asTemplateDeclaration() ? enclosingAST : funcAST; completeDefAST = enclosingAST->asTemplateDeclaration() ? enclosingAST : funcAST;
break; break;
} }
funcAST = 0; funcAST = nullptr;
} }
} }
@@ -5196,7 +5171,7 @@ public:
setDescription(QApplication::translate("CppTools::QuickFix", "Assign to Local Variable")); setDescription(QApplication::translate("CppTools::QuickFix", "Assign to Local Variable"));
} }
void perform() void perform() override
{ {
CppRefactoringChanges refactoring(snapshot()); CppRefactoringChanges refactoring(snapshot());
CppRefactoringFilePtr file = refactoring.file(fileName()); CppRefactoringFilePtr file = refactoring.file(fileName());
@@ -5271,8 +5246,8 @@ private:
void AssignToLocalVariable::match(const CppQuickFixInterface &interface, QuickFixOperations &result) void AssignToLocalVariable::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{ {
const QList<AST *> &path = interface.path(); const QList<AST *> &path = interface.path();
AST *outerAST = 0; AST *outerAST = nullptr;
SimpleNameAST *nameAST = 0; SimpleNameAST *nameAST = nullptr;
for (int i = path.size() - 3; i >= 0; --i) { for (int i = path.size() - 3; i >= 0; --i) {
if (CallAST *callAST = path.at(i)->asCall()) { if (CallAST *callAST = path.at(i)->asCall()) {
@@ -5404,7 +5379,7 @@ public:
setDescription(QApplication::translate("CppTools::QuickFix", "Optimize for-Loop")); setDescription(QApplication::translate("CppTools::QuickFix", "Optimize for-Loop"));
} }
void perform() void perform() override
{ {
QTC_ASSERT(m_forAst, return); QTC_ASSERT(m_forAst, return);
@@ -5491,7 +5466,7 @@ private:
void OptimizeForLoop::match(const CppQuickFixInterface &interface, QuickFixOperations &result) void OptimizeForLoop::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
{ {
const QList<AST *> path = interface.path(); const QList<AST *> path = interface.path();
ForStatementAST *forAst = 0; ForStatementAST *forAst = nullptr;
if (!path.isEmpty()) if (!path.isEmpty())
forAst = path.last()->asForStatement(); forAst = path.last()->asForStatement();
if (!forAst || !interface.isCursorOn(forAst)) if (!forAst || !interface.isCursorOn(forAst))
@@ -5511,7 +5486,7 @@ void OptimizeForLoop::match(const CppQuickFixInterface &interface, QuickFixOpera
// Check for optimizing condition // Check for optimizing condition
bool optimizeCondition = false; bool optimizeCondition = false;
FullySpecifiedType conditionType; FullySpecifiedType conditionType;
ExpressionAST *conditionExpression = 0; ExpressionAST *conditionExpression = nullptr;
if (forAst->initializer && forAst->condition) { if (forAst->initializer && forAst->condition) {
if (BinaryExpressionAST *binary = forAst->condition->asBinaryExpression()) { if (BinaryExpressionAST *binary = forAst->condition->asBinaryExpression()) {
// Get the expression against which we should evaluate // Get the expression against which we should evaluate
@@ -5563,7 +5538,7 @@ void OptimizeForLoop::match(const CppQuickFixInterface &interface, QuickFixOpera
if (optimizePostcrement || optimizeCondition) { if (optimizePostcrement || optimizeCondition) {
result << new OptimizeForLoopOperation(interface, forAst, optimizePostcrement, result << new OptimizeForLoopOperation(interface, forAst, optimizePostcrement,
(optimizeCondition) ? conditionExpression : 0, optimizeCondition ? conditionExpression : nullptr,
conditionType); conditionType);
} }
} }
@@ -5661,7 +5636,7 @@ private:
// QuickFixOperation interface // QuickFixOperation interface
public: public:
void perform() void perform() override
{ {
CppRefactoringChanges refactoring(snapshot()); CppRefactoringChanges refactoring(snapshot());
CppRefactoringFilePtr currentFile = refactoring.file(fileName()); CppRefactoringFilePtr currentFile = refactoring.file(fileName());
@@ -5748,7 +5723,7 @@ public:
} }
private: private:
void perform() void perform() override
{ {
CppRefactoringChanges refactoring(snapshot()); CppRefactoringChanges refactoring(snapshot());
CppRefactoringFilePtr currentFile = refactoring.file(fileName()); CppRefactoringFilePtr currentFile = refactoring.file(fileName());
@@ -5766,7 +5741,7 @@ Symbol *skipForwardDeclarations(const QList<Symbol *> &symbols)
return symbol; return symbol;
} }
return 0; return nullptr;
} }
bool findRawAccessFunction(Class *klass, PointerType *pointerType, QString *objAccessFunction) bool findRawAccessFunction(Class *klass, PointerType *pointerType, QString *objAccessFunction)
@@ -5784,7 +5759,7 @@ bool findRawAccessFunction(Class *klass, PointerType *pointerType, QString *objA
} }
} }
} }
const Name *funcName = 0; const Name *funcName = nullptr;
switch (candidates.size()) { switch (candidates.size()) {
case 0: case 0:
return false; return false;
@@ -5811,7 +5786,7 @@ PointerType *determineConvertedType(NamedType *namedType, const LookupContext &c
Scope *scope, QString *objAccessFunction) Scope *scope, QString *objAccessFunction)
{ {
if (!namedType) if (!namedType)
return 0; return nullptr;
if (ClassOrNamespace *binding = context.lookupType(namedType->name(), scope)) { if (ClassOrNamespace *binding = context.lookupType(namedType->name(), scope)) {
if (Symbol *objectClassSymbol = skipForwardDeclarations(binding->symbols())) { if (Symbol *objectClassSymbol = skipForwardDeclarations(binding->symbols())) {
if (Class *klass = objectClassSymbol->asClass()) { if (Class *klass = objectClassSymbol->asClass()) {
@@ -5830,7 +5805,7 @@ PointerType *determineConvertedType(NamedType *namedType, const LookupContext &c
} }
} }
return 0; return nullptr;
} }
Class *senderOrReceiverClass(const CppQuickFixInterface &interface, Class *senderOrReceiverClass(const CppQuickFixInterface &interface,
@@ -5852,33 +5827,33 @@ Class *senderOrReceiverClass(const CppQuickFixInterface &interface,
toe.init(interface.semanticInfo().doc, interface.snapshot(), context.bindings()); toe.init(interface.semanticInfo().doc, interface.snapshot(), context.bindings());
const QList<LookupItem> objectPointerExpressions = toe(objectPointerExpression, const QList<LookupItem> objectPointerExpressions = toe(objectPointerExpression,
objectPointerScope, TypeOfExpression::Preprocess); objectPointerScope, TypeOfExpression::Preprocess);
QTC_ASSERT(objectPointerExpressions.size() == 1, return 0); QTC_ASSERT(objectPointerExpressions.size() == 1, return nullptr);
Type *objectPointerTypeBase = objectPointerExpressions.first().type().type(); Type *objectPointerTypeBase = objectPointerExpressions.first().type().type();
QTC_ASSERT(objectPointerTypeBase, return 0); QTC_ASSERT(objectPointerTypeBase, return nullptr);
PointerType *objectPointerType = objectPointerTypeBase->asPointerType(); PointerType *objectPointerType = objectPointerTypeBase->asPointerType();
if (!objectPointerType) { if (!objectPointerType) {
objectPointerType = determineConvertedType(objectPointerTypeBase->asNamedType(), context, objectPointerType = determineConvertedType(objectPointerTypeBase->asNamedType(), context,
objectPointerScope, objAccessFunction); objectPointerScope, objAccessFunction);
} }
QTC_ASSERT(objectPointerType, return 0); QTC_ASSERT(objectPointerType, return nullptr);
Type *objectTypeBase = objectPointerType->elementType().type(); // Dereference Type *objectTypeBase = objectPointerType->elementType().type(); // Dereference
QTC_ASSERT(objectTypeBase, return 0); QTC_ASSERT(objectTypeBase, return nullptr);
NamedType *objectType = objectTypeBase->asNamedType(); NamedType *objectType = objectTypeBase->asNamedType();
QTC_ASSERT(objectType, return 0); QTC_ASSERT(objectType, return nullptr);
ClassOrNamespace *objectClassCON = context.lookupType(objectType->name(), objectPointerScope); ClassOrNamespace *objectClassCON = context.lookupType(objectType->name(), objectPointerScope);
if (!objectClassCON) { if (!objectClassCON) {
objectClassCON = objectPointerExpressions.first().binding(); objectClassCON = objectPointerExpressions.first().binding();
QTC_ASSERT(objectClassCON, return 0); QTC_ASSERT(objectClassCON, return nullptr);
} }
QTC_ASSERT(!objectClassCON->symbols().isEmpty(), return 0); QTC_ASSERT(!objectClassCON->symbols().isEmpty(), return nullptr);
Symbol *objectClassSymbol = skipForwardDeclarations(objectClassCON->symbols()); Symbol *objectClassSymbol = skipForwardDeclarations(objectClassCON->symbols());
QTC_ASSERT(objectClassSymbol, return 0); QTC_ASSERT(objectClassSymbol, return nullptr);
return objectClassSymbol->asClass(); return objectClassSymbol->asClass();
} }
@@ -5992,7 +5967,7 @@ bool collectConnectArguments(const ExpressionListAST *arguments,
// Take care of three-arg version, with 'this' receiver. // Take care of three-arg version, with 'this' receiver.
if (QtMethodAST *receiverMethod = arguments->value->asQtMethod()) { if (QtMethodAST *receiverMethod = arguments->value->asQtMethod()) {
*arg3 = 0; // Means 'this' *arg3 = nullptr; // Means 'this'
*arg4 = receiverMethod; *arg4 = receiverMethod;
return true; return true;
} }

View File

@@ -65,7 +65,7 @@ class AddIncludeForUndefinedIdentifierOp: public CppQuickFixOperation
public: public:
AddIncludeForUndefinedIdentifierOp(const CppQuickFixInterface &interface, int priority, AddIncludeForUndefinedIdentifierOp(const CppQuickFixInterface &interface, int priority,
const QString &include); const QString &include);
void perform(); void perform() override;
private: private:
QString m_include; QString m_include;
@@ -383,7 +383,7 @@ public:
class ExtractFunction : public CppQuickFixFactory class ExtractFunction : public CppQuickFixFactory
{ {
public: public:
typedef std::function<QString ()> FunctionNameGetter; using FunctionNameGetter = std::function<QString()>;
ExtractFunction(FunctionNameGetter functionNameGetter = FunctionNameGetter()); ExtractFunction(FunctionNameGetter functionNameGetter = FunctionNameGetter());
void match(const CppQuickFixInterface &interface, TextEditor::QuickFixOperations &result) override; void match(const CppQuickFixInterface &interface, TextEditor::QuickFixOperations &result) override;

View File

@@ -59,7 +59,7 @@ enum ItemRole {
QStandardItem *itemForClass(const CppClass &cppClass) QStandardItem *itemForClass(const CppClass &cppClass)
{ {
QStandardItem *item = new QStandardItem; auto item = new QStandardItem;
item->setFlags(item->flags() | Qt::ItemIsDragEnabled); item->setFlags(item->flags() | Qt::ItemIsDragEnabled);
item->setData(cppClass.name, Qt::DisplayRole); item->setData(cppClass.name, Qt::DisplayRole);
if (cppClass.name != cppClass.qualifiedName) if (cppClass.name != cppClass.qualifiedName)
@@ -88,8 +88,7 @@ namespace CppEditor {
namespace Internal { namespace Internal {
// CppTypeHierarchyWidget // CppTypeHierarchyWidget
CppTypeHierarchyWidget::CppTypeHierarchyWidget() : CppTypeHierarchyWidget::CppTypeHierarchyWidget()
QWidget(0)
{ {
m_inspectedClass = new TextEditor::TextEditorLinkLabel(this); m_inspectedClass = new TextEditor::TextEditorLinkLabel(this);
m_inspectedClass->setMargin(5); m_inspectedClass->setMargin(5);
@@ -114,7 +113,7 @@ CppTypeHierarchyWidget::CppTypeHierarchyWidget() :
m_noTypeHierarchyAvailableLabel->setBackgroundRole(QPalette::Base); m_noTypeHierarchyAvailableLabel->setBackgroundRole(QPalette::Base);
m_hierarchyWidget = new QWidget(this); m_hierarchyWidget = new QWidget(this);
QVBoxLayout *layout = new QVBoxLayout; auto layout = new QVBoxLayout;
layout->setMargin(0); layout->setMargin(0);
layout->setSpacing(0); layout->setSpacing(0);
layout->addWidget(m_inspectedClass); layout->addWidget(m_inspectedClass);
@@ -130,18 +129,17 @@ CppTypeHierarchyWidget::CppTypeHierarchyWidget() :
connect(CppEditorPlugin::instance(), &CppEditorPlugin::typeHierarchyRequested, this, &CppTypeHierarchyWidget::perform); connect(CppEditorPlugin::instance(), &CppEditorPlugin::typeHierarchyRequested, this, &CppTypeHierarchyWidget::perform);
} }
CppTypeHierarchyWidget::~CppTypeHierarchyWidget() CppTypeHierarchyWidget::~CppTypeHierarchyWidget() = default;
{}
void CppTypeHierarchyWidget::perform() void CppTypeHierarchyWidget::perform()
{ {
showNoTypeHierarchyLabel(); showNoTypeHierarchyLabel();
CppEditor *editor = qobject_cast<CppEditor *>(Core::EditorManager::currentEditor()); auto editor = qobject_cast<CppEditor *>(Core::EditorManager::currentEditor());
if (!editor) if (!editor)
return; return;
CppEditorWidget *widget = qobject_cast<CppEditorWidget *>(editor->widget()); auto widget = qobject_cast<CppEditorWidget *>(editor->widget());
if (!widget) if (!widget)
return; return;

View File

@@ -61,9 +61,9 @@ class CppTypeHierarchyModel : public QStandardItemModel
public: public:
CppTypeHierarchyModel(QObject *parent); CppTypeHierarchyModel(QObject *parent);
Qt::DropActions supportedDragActions() const; Qt::DropActions supportedDragActions() const override;
QStringList mimeTypes() const; QStringList mimeTypes() const override;
QMimeData *mimeData(const QModelIndexList &indexes) const; QMimeData *mimeData(const QModelIndexList &indexes) const override;
}; };
class CppTypeHierarchyWidget : public QWidget class CppTypeHierarchyWidget : public QWidget
@@ -71,7 +71,7 @@ class CppTypeHierarchyWidget : public QWidget
Q_OBJECT Q_OBJECT
public: public:
CppTypeHierarchyWidget(); CppTypeHierarchyWidget();
virtual ~CppTypeHierarchyWidget(); ~CppTypeHierarchyWidget() override;
void perform(); void perform();

View File

@@ -44,7 +44,7 @@ class CppUseSelectionsUpdater : public QObject
public: public:
explicit CppUseSelectionsUpdater(TextEditor::TextEditorWidget *editorWidget); explicit CppUseSelectionsUpdater(TextEditor::TextEditorWidget *editorWidget);
~CppUseSelectionsUpdater(); ~CppUseSelectionsUpdater() override;
void scheduleUpdate(); void scheduleUpdate();
void abortSchedule(); void abortSchedule();