From 667f8563bc6ca27c9f6a32bb9e0c0da7f35c48f3 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Wed, 10 Feb 2021 11:11:00 +0100 Subject: [PATCH] CppEditor: Move ast path checker to relevant quick fix provider We have quick fix factories that do not require an ast path at the cursor position nowadays, for example the quick fix factories that provide fixes from the clang tools. Move the check to those factories that rely on a valid ast. Change-Id: Iab4b30d5935fbd32f101fb5fda60e994f14dc94c Reviewed-by: Christian Kandeler --- src/plugins/cppeditor/cppquickfixassistant.cpp | 2 -- src/plugins/cppeditor/cppquickfixes.cpp | 8 ++++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/plugins/cppeditor/cppquickfixassistant.cpp b/src/plugins/cppeditor/cppquickfixassistant.cpp index cbf78296bc6..474144e9687 100644 --- a/src/plugins/cppeditor/cppquickfixassistant.cpp +++ b/src/plugins/cppeditor/cppquickfixassistant.cpp @@ -57,8 +57,6 @@ class CppQuickFixAssistProcessor : public IAssistProcessor { QSharedPointer assistInterface(interface); auto cppInterface = assistInterface.staticCast(); - if (cppInterface->path().isEmpty()) - return nullptr; QuickFixOperations quickFixes; for (CppQuickFixFactory *factory : CppQuickFixFactory::cppQuickFixFactories()) diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp index f0d205215af..f1a2d78b0ed 100644 --- a/src/plugins/cppeditor/cppquickfixes.cpp +++ b/src/plugins/cppeditor/cppquickfixes.cpp @@ -750,6 +750,8 @@ void InverseLogicalComparison::match(const CppQuickFixInterface &interface, CppRefactoringFilePtr file = interface.currentFile(); const QList &path = interface.path(); + if (path.isEmpty()) + return; int index = path.size() - 1; BinaryExpressionAST *binary = path.at(index)->asBinaryExpression(); if (!binary) @@ -831,6 +833,8 @@ private: void FlipLogicalOperands::match(const CppQuickFixInterface &interface, QuickFixOperations &result) { const QList &path = interface.path(); + if (path.isEmpty()) + return; CppRefactoringFilePtr file = interface.currentFile(); int index = path.size() - 1; @@ -1098,6 +1102,8 @@ private: void AddBracesToIf::match(const CppQuickFixInterface &interface, QuickFixOperations &result) { const QList &path = interface.path(); + if (path.isEmpty()) + return; // show when we're on the 'if' of an if statement int index = path.size() - 1; @@ -7520,6 +7526,8 @@ private: void EscapeStringLiteral::match(const CppQuickFixInterface &interface, QuickFixOperations &result) { const QList &path = interface.path(); + if (path.isEmpty()) + return; AST * const lastAst = path.last(); ExpressionAST *literal = lastAst->asStringLiteral();