forked from qt-creator/qt-creator
CppQuickFixes: Add function getDeclaration for AddLocalDeclaration
Change-Id: Ie2d5c5de6b871a855b95efe7c633b28d6ed5c512 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -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());
|
||||
@@ -1622,9 +1639,9 @@ public:
|
||||
typeOfExpression.init(semanticInfo().doc, snapshot(), context().bindings());
|
||||
Scope *scope = currentFile->scopeAt(binaryAST->firstToken());
|
||||
const QList<LookupItem> result =
|
||||
typeOfExpression(currentFile->textOf(binaryAST->right_expression).toUtf8(),
|
||||
scope,
|
||||
TypeOfExpression::Preprocess);
|
||||
typeOfExpression(currentFile->textOf(binaryAST->right_expression).toUtf8(),
|
||||
scope,
|
||||
TypeOfExpression::Preprocess);
|
||||
|
||||
if (!result.isEmpty()) {
|
||||
SubstitutionEnvironment env;
|
||||
@@ -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;
|
||||
};
|
||||
|
Reference in New Issue
Block a user