CppQuickFixes: Add function getDeclaration for AddLocalDeclaration

Change-Id: Ie2d5c5de6b871a855b95efe7c633b28d6ed5c512
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Artem Sokolovskii
2022-06-16 10:39:21 +02:00
parent 677a8fe34a
commit 706dc654b9

View File

@@ -1614,6 +1614,23 @@ public:
}
void perform() override
{
CppRefactoringChanges refactoring(snapshot());
CppRefactoringFilePtr currentFile = refactoring.file(filePath());
QString declaration = getDeclaration();
if (!declaration.isEmpty()) {
ChangeSet changes;
changes.replace(currentFile->startOf(binaryAST),
currentFile->endOf(simpleNameAST),
declaration);
currentFile->setChangeSet(changes);
currentFile->apply();
}
}
private:
QString getDeclaration()
{
CppRefactoringChanges refactoring(snapshot());
CppRefactoringFilePtr currentFile = refactoring.file(filePath());
@@ -1640,19 +1657,13 @@ public:
FullySpecifiedType tn = rewriteType(result.first().type(), &env, control);
Overview oo = CppCodeStyleSettings::currentProjectCodeStyleOverview();
QString ty = oo.prettyType(tn, simpleNameAST->name);
if (!ty.isEmpty()) {
ChangeSet changes;
changes.replace(currentFile->startOf(binaryAST),
currentFile->endOf(simpleNameAST),
ty);
currentFile->setChangeSet(changes);
currentFile->apply();
}
}
QString declaration = oo.prettyType(tn, simpleNameAST->name);
return declaration;
}
return {};
}
private:
const BinaryExpressionAST *binaryAST;
const SimpleNameAST *simpleNameAST;
};