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 <christian.kandeler@qt.io>
This commit is contained in:
David Schulz
2021-02-10 11:11:00 +01:00
parent 0f315f62b1
commit 667f8563bc
2 changed files with 8 additions and 2 deletions

View File

@@ -57,8 +57,6 @@ class CppQuickFixAssistProcessor : public IAssistProcessor
{
QSharedPointer<const AssistInterface> assistInterface(interface);
auto cppInterface = assistInterface.staticCast<const CppQuickFixInterface>();
if (cppInterface->path().isEmpty())
return nullptr;
QuickFixOperations quickFixes;
for (CppQuickFixFactory *factory : CppQuickFixFactory::cppQuickFixFactories())

View File

@@ -750,6 +750,8 @@ void InverseLogicalComparison::match(const CppQuickFixInterface &interface,
CppRefactoringFilePtr file = interface.currentFile();
const QList<AST *> &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<AST *> &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<AST *> &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<AST *> &path = interface.path();
if (path.isEmpty())
return;
AST * const lastAst = path.last();
ExpressionAST *literal = lastAst->asStringLiteral();