forked from qt-creator/qt-creator
TextEditor: Add a convenience append method for quick fixes
Less noise on the user side. Change-Id: Ia5b495a1f9d3ec43623056d793f6771b3b84fd6b Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
@@ -114,7 +114,7 @@ public:
|
|||||||
CppLocalRenaming m_localRenaming;
|
CppLocalRenaming m_localRenaming;
|
||||||
|
|
||||||
CppTools::SemanticInfo m_lastSemanticInfo;
|
CppTools::SemanticInfo m_lastSemanticInfo;
|
||||||
QList<QuickFixOperation::Ptr> m_quickFixes;
|
QuickFixOperations m_quickFixes;
|
||||||
|
|
||||||
CppUseSelectionsUpdater m_useSelectionsUpdater;
|
CppUseSelectionsUpdater m_useSelectionsUpdater;
|
||||||
|
|
||||||
@@ -474,8 +474,7 @@ bool CppEditorWidget::event(QEvent *e)
|
|||||||
|
|
||||||
void CppEditorWidget::performQuickFix(int index)
|
void CppEditorWidget::performQuickFix(int index)
|
||||||
{
|
{
|
||||||
QuickFixOperation::Ptr op = d->m_quickFixes.at(index);
|
d->m_quickFixes.at(index)->perform();
|
||||||
op->perform();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppEditorWidget::processKeyNormally(QKeyEvent *e)
|
void CppEditorWidget::processKeyNormally(QKeyEvent *e)
|
||||||
|
|||||||
@@ -1088,7 +1088,7 @@ void InsertVirtualMethods::match(const CppQuickFixInterface &interface, QuickFix
|
|||||||
{
|
{
|
||||||
InsertVirtualMethodsOp *op = new InsertVirtualMethodsOp(interface, m_dialog);
|
InsertVirtualMethodsOp *op = new InsertVirtualMethodsOp(interface, m_dialog);
|
||||||
if (op->isValid())
|
if (op->isValid())
|
||||||
result.append(QuickFixOperation::Ptr(op));
|
result.append(op);
|
||||||
else
|
else
|
||||||
delete op;
|
delete op;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -234,8 +234,7 @@ public:
|
|||||||
|
|
||||||
void match(const CppQuickFixInterface &cppQuickFixInterface, QuickFixOperations &result)
|
void match(const CppQuickFixInterface &cppQuickFixInterface, QuickFixOperations &result)
|
||||||
{
|
{
|
||||||
result += CppQuickFixOperation::Ptr(
|
result.append(new AddIncludeForUndefinedIdentifierOp(cppQuickFixInterface, 0, m_include));
|
||||||
new AddIncludeForUndefinedIdentifierOp(cppQuickFixInterface, 0, m_include));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -395,8 +395,7 @@ void InverseLogicalComparison::match(const CppQuickFixInterface &interface,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
result.append(CppQuickFixOperation::Ptr(
|
result.append(new InverseLogicalComparisonOp(interface, index, binary, invertToken));
|
||||||
new InverseLogicalComparisonOp(interface, index, binary, invertToken)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -486,8 +485,7 @@ void FlipLogicalOperands::match(const CppQuickFixInterface &interface, QuickFixO
|
|||||||
replacement = QLatin1String(tok.spell());
|
replacement = QLatin1String(tok.spell());
|
||||||
}
|
}
|
||||||
|
|
||||||
result.append(QuickFixOperation::Ptr(
|
result.append(new FlipLogicalOperandsOp(interface, index, binary, replacement));
|
||||||
new FlipLogicalOperandsOp(interface, index, binary, replacement)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -666,15 +664,13 @@ void SplitSimpleDeclaration::match(const CppQuickFixInterface &interface,
|
|||||||
|
|
||||||
if (cursorPosition >= startOfDeclSpecifier && cursorPosition <= endOfDeclSpecifier) {
|
if (cursorPosition >= startOfDeclSpecifier && cursorPosition <= endOfDeclSpecifier) {
|
||||||
// the AST node under cursor is a specifier.
|
// the AST node under cursor is a specifier.
|
||||||
result.append(QuickFixOperation::Ptr(
|
result.append(new SplitSimpleDeclarationOp(interface, index, declaration));
|
||||||
new SplitSimpleDeclarationOp(interface, index, declaration)));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (core_declarator && interface->isCursorOn(core_declarator)) {
|
if (core_declarator && interface->isCursorOn(core_declarator)) {
|
||||||
// got a core-declarator under the text cursor.
|
// got a core-declarator under the text cursor.
|
||||||
result.append(QuickFixOperation::Ptr(
|
result.append(new SplitSimpleDeclarationOp(interface, index, declaration));
|
||||||
new SplitSimpleDeclarationOp(interface, index, declaration)));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -729,8 +725,7 @@ void AddBracesToIf::match(const CppQuickFixInterface &interface, QuickFixOperati
|
|||||||
IfStatementAST *ifStatement = path.at(index)->asIfStatement();
|
IfStatementAST *ifStatement = path.at(index)->asIfStatement();
|
||||||
if (ifStatement && interface->isCursorOn(ifStatement->if_token) && ifStatement->statement
|
if (ifStatement && interface->isCursorOn(ifStatement->if_token) && ifStatement->statement
|
||||||
&& !ifStatement->statement->asCompoundStatement()) {
|
&& !ifStatement->statement->asCompoundStatement()) {
|
||||||
result.append(QuickFixOperation::Ptr(
|
result.append(new AddBracesToIfOp(interface, index, ifStatement->statement));
|
||||||
new AddBracesToIfOp(interface, index, ifStatement->statement)));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -741,8 +736,7 @@ void AddBracesToIf::match(const CppQuickFixInterface &interface, QuickFixOperati
|
|||||||
if (ifStatement && ifStatement->statement
|
if (ifStatement && ifStatement->statement
|
||||||
&& interface->isCursorOn(ifStatement->statement)
|
&& interface->isCursorOn(ifStatement->statement)
|
||||||
&& !ifStatement->statement->asCompoundStatement()) {
|
&& !ifStatement->statement->asCompoundStatement()) {
|
||||||
result.append(QuickFixOperation::Ptr(
|
result.append(new AddBracesToIfOp(interface, index, ifStatement->statement));
|
||||||
new AddBracesToIfOp(interface, index, ifStatement->statement)));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1030,8 +1024,7 @@ void SplitIfStatement::match(const CppQuickFixInterface &interface, QuickFixOper
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (interface->isCursorOn(condition->binary_op_token)) {
|
if (interface->isCursorOn(condition->binary_op_token)) {
|
||||||
result.append(QuickFixOperation::Ptr(
|
result.append(new SplitIfStatementOp(interface, index, pattern, condition));
|
||||||
new SplitIfStatementOp(interface, index, pattern, condition)));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1172,8 +1165,6 @@ private:
|
|||||||
|
|
||||||
void WrapStringLiteral::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
|
void WrapStringLiteral::match(const CppQuickFixInterface &interface, QuickFixOperations &result)
|
||||||
{
|
{
|
||||||
typedef CppQuickFixOperation::Ptr OperationPtr;
|
|
||||||
|
|
||||||
Type type = TypeNone;
|
Type type = TypeNone;
|
||||||
QByteArray enclosingFunction;
|
QByteArray enclosingFunction;
|
||||||
const QList<AST *> &path = interface->path();
|
const QList<AST *> &path = interface->path();
|
||||||
@@ -1190,15 +1181,14 @@ void WrapStringLiteral::match(const CppQuickFixInterface &interface, QuickFixOpe
|
|||||||
if (type == TypeChar) {
|
if (type == TypeChar) {
|
||||||
unsigned actions = EncloseInQLatin1CharAction;
|
unsigned actions = EncloseInQLatin1CharAction;
|
||||||
QString description = msgQtStringLiteralDescription(replacement(actions));
|
QString description = msgQtStringLiteralDescription(replacement(actions));
|
||||||
result << OperationPtr(new WrapStringLiteralOp(interface, priority, actions,
|
result.append(new WrapStringLiteralOp(interface, priority, actions, description, literal));
|
||||||
description, literal));
|
|
||||||
if (NumericLiteralAST *charLiteral = literal->asNumericLiteral()) {
|
if (NumericLiteralAST *charLiteral = literal->asNumericLiteral()) {
|
||||||
const QByteArray contents(file->tokenAt(charLiteral->literal_token).identifier->chars());
|
const QByteArray contents(file->tokenAt(charLiteral->literal_token).identifier->chars());
|
||||||
if (!charToStringEscapeSequences(contents).isEmpty()) {
|
if (!charToStringEscapeSequences(contents).isEmpty()) {
|
||||||
actions = DoubleQuoteAction | ConvertEscapeSequencesToStringAction;
|
actions = DoubleQuoteAction | ConvertEscapeSequencesToStringAction;
|
||||||
description = QApplication::translate("CppTools::QuickFix",
|
description = QApplication::translate("CppTools::QuickFix",
|
||||||
"Convert to String Literal");
|
"Convert to String Literal");
|
||||||
result << OperationPtr(new WrapStringLiteralOp(interface, priority, actions,
|
result.append(new WrapStringLiteralOp(interface, priority, actions,
|
||||||
description, literal));
|
description, literal));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1213,23 +1203,20 @@ void WrapStringLiteral::match(const CppQuickFixInterface &interface, QuickFixOpe
|
|||||||
| ConvertEscapeSequencesToCharAction | objectiveCActions;
|
| ConvertEscapeSequencesToCharAction | objectiveCActions;
|
||||||
QString description = QApplication::translate("CppTools::QuickFix",
|
QString description = QApplication::translate("CppTools::QuickFix",
|
||||||
"Convert to Character Literal and Enclose in QLatin1Char(...)");
|
"Convert to Character Literal and Enclose in QLatin1Char(...)");
|
||||||
result << OperationPtr(new WrapStringLiteralOp(interface, priority, actions,
|
result.append(new WrapStringLiteralOp(interface, priority, actions,
|
||||||
description, literal));
|
description, literal));
|
||||||
actions &= ~EncloseInQLatin1CharAction;
|
actions &= ~EncloseInQLatin1CharAction;
|
||||||
description = QApplication::translate("CppTools::QuickFix",
|
description = QApplication::translate("CppTools::QuickFix",
|
||||||
"Convert to Character Literal");
|
"Convert to Character Literal");
|
||||||
result << OperationPtr(new WrapStringLiteralOp(interface, priority, actions,
|
result.append(new WrapStringLiteralOp(interface, priority, actions,
|
||||||
description, literal));
|
description, literal));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
actions = EncloseInQLatin1StringAction | objectiveCActions;
|
actions = EncloseInQLatin1StringAction | objectiveCActions;
|
||||||
result << OperationPtr(
|
result.append(new WrapStringLiteralOp(interface, priority, actions,
|
||||||
new WrapStringLiteralOp(interface, priority, actions,
|
msgQtStringLiteralDescription(replacement(actions), 4), literal));
|
||||||
msgQtStringLiteralDescription(replacement(actions), 4),
|
|
||||||
literal));
|
|
||||||
actions = EncloseInQStringLiteralAction | objectiveCActions;
|
actions = EncloseInQStringLiteralAction | objectiveCActions;
|
||||||
result << OperationPtr(
|
result.append(new WrapStringLiteralOp(interface, priority, actions,
|
||||||
new WrapStringLiteralOp(interface, priority, actions,
|
|
||||||
msgQtStringLiteralDescription(replacement(actions), 5), literal));
|
msgQtStringLiteralDescription(replacement(actions), 5), literal));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1315,10 +1302,9 @@ void TranslateStringLiteral::match(const CppQuickFixInterface &interface,
|
|||||||
Symbol *s = r.declaration();
|
Symbol *s = r.declaration();
|
||||||
if (s->type()->isFunctionType()) {
|
if (s->type()->isFunctionType()) {
|
||||||
// no context required for tr
|
// no context required for tr
|
||||||
result.append(QuickFixOperation::Ptr(
|
result.append(new WrapStringLiteralOp(interface, path.size() - 1,
|
||||||
new WrapStringLiteralOp(interface, path.size() - 1,
|
|
||||||
WrapStringLiteral::TranslateTrAction,
|
WrapStringLiteral::TranslateTrAction,
|
||||||
description, literal)));
|
description, literal));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1334,19 +1320,17 @@ void TranslateStringLiteral::match(const CppQuickFixInterface &interface,
|
|||||||
// ... or global if none available!
|
// ... or global if none available!
|
||||||
if (trContext.isEmpty())
|
if (trContext.isEmpty())
|
||||||
trContext = QLatin1String("GLOBAL");
|
trContext = QLatin1String("GLOBAL");
|
||||||
result.append(QuickFixOperation::Ptr(
|
result.append(new WrapStringLiteralOp(interface, path.size() - 1,
|
||||||
new WrapStringLiteralOp(interface, path.size() - 1,
|
|
||||||
WrapStringLiteral::TranslateQCoreApplicationAction,
|
WrapStringLiteral::TranslateQCoreApplicationAction,
|
||||||
description, literal, trContext)));
|
description, literal, trContext));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We need to use Q_TRANSLATE_NOOP
|
// We need to use Q_TRANSLATE_NOOP
|
||||||
result.append(QuickFixOperation::Ptr(
|
result.append(new WrapStringLiteralOp(interface, path.size() - 1,
|
||||||
new WrapStringLiteralOp(interface, path.size() - 1,
|
|
||||||
WrapStringLiteral::TranslateNoopAction,
|
WrapStringLiteral::TranslateNoopAction,
|
||||||
description, literal, trContext)));
|
description, literal, trContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -1409,9 +1393,8 @@ void ConvertCStringToNSString::match(const CppQuickFixInterface &interface,
|
|||||||
if (!isQtStringLiteral(enclosingFunction))
|
if (!isQtStringLiteral(enclosingFunction))
|
||||||
qlatin1Call = 0;
|
qlatin1Call = 0;
|
||||||
|
|
||||||
result.append(QuickFixOperation::Ptr(
|
result.append(new ConvertCStringToNSStringOp(interface, path.size() - 1, literal->asStringLiteral(),
|
||||||
new ConvertCStringToNSStringOp(interface, path.size() - 1, literal->asStringLiteral(),
|
qlatin1Call));
|
||||||
qlatin1Call)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -1495,8 +1478,7 @@ void ConvertNumericLiteral::match(const CppQuickFixInterface &interface, QuickFi
|
|||||||
*/
|
*/
|
||||||
QString replacement;
|
QString replacement;
|
||||||
replacement.sprintf("0x%lX", value);
|
replacement.sprintf("0x%lX", value);
|
||||||
QuickFixOperation::Ptr op(
|
auto op = new ConvertNumericLiteralOp(interface, start, start + numberLength, replacement);
|
||||||
new ConvertNumericLiteralOp(interface, start, start + numberLength, replacement));
|
|
||||||
op->setDescription(QApplication::translate("CppTools::QuickFix", "Convert to Hexadecimal"));
|
op->setDescription(QApplication::translate("CppTools::QuickFix", "Convert to Hexadecimal"));
|
||||||
op->setPriority(priority);
|
op->setPriority(priority);
|
||||||
result.append(op);
|
result.append(op);
|
||||||
@@ -1514,8 +1496,7 @@ void ConvertNumericLiteral::match(const CppQuickFixInterface &interface, QuickFi
|
|||||||
*/
|
*/
|
||||||
QString replacement;
|
QString replacement;
|
||||||
replacement.sprintf("0%lo", value);
|
replacement.sprintf("0%lo", value);
|
||||||
QuickFixOperation::Ptr op(
|
auto op = new ConvertNumericLiteralOp(interface, start, start + numberLength, replacement);
|
||||||
new ConvertNumericLiteralOp(interface, start, start + numberLength, replacement));
|
|
||||||
op->setDescription(QApplication::translate("CppTools::QuickFix", "Convert to Octal"));
|
op->setDescription(QApplication::translate("CppTools::QuickFix", "Convert to Octal"));
|
||||||
op->setPriority(priority);
|
op->setPriority(priority);
|
||||||
result.append(op);
|
result.append(op);
|
||||||
@@ -1534,8 +1515,7 @@ void ConvertNumericLiteral::match(const CppQuickFixInterface &interface, QuickFi
|
|||||||
*/
|
*/
|
||||||
QString replacement;
|
QString replacement;
|
||||||
replacement.sprintf("%lu", value);
|
replacement.sprintf("%lu", value);
|
||||||
QuickFixOperation::Ptr op(
|
auto op = new ConvertNumericLiteralOp(interface, start, start + numberLength, replacement);
|
||||||
new ConvertNumericLiteralOp(interface, start, start + numberLength, replacement));
|
|
||||||
op->setDescription(QApplication::translate("CppTools::QuickFix", "Convert to Decimal"));
|
op->setDescription(QApplication::translate("CppTools::QuickFix", "Convert to Decimal"));
|
||||||
op->setPriority(priority);
|
op->setPriority(priority);
|
||||||
result.append(op);
|
result.append(op);
|
||||||
@@ -1647,15 +1627,13 @@ void AddIncludeForForwardDeclaration::match(const CppQuickFixInterface &interfac
|
|||||||
if (NamedTypeSpecifierAST *namedTy = ast->asNamedTypeSpecifier()) {
|
if (NamedTypeSpecifierAST *namedTy = ast->asNamedTypeSpecifier()) {
|
||||||
if (Symbol *fwdClass = AddIncludeForForwardDeclarationOp::checkName(interface,
|
if (Symbol *fwdClass = AddIncludeForForwardDeclarationOp::checkName(interface,
|
||||||
namedTy->name)) {
|
namedTy->name)) {
|
||||||
result.append(QuickFixOperation::Ptr(
|
result.append(new AddIncludeForForwardDeclarationOp(interface, index, fwdClass));
|
||||||
new AddIncludeForForwardDeclarationOp(interface, index, fwdClass)));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (ElaboratedTypeSpecifierAST *eTy = ast->asElaboratedTypeSpecifier()) {
|
} else if (ElaboratedTypeSpecifierAST *eTy = ast->asElaboratedTypeSpecifier()) {
|
||||||
if (Symbol *fwdClass = AddIncludeForForwardDeclarationOp::checkName(interface,
|
if (Symbol *fwdClass = AddIncludeForForwardDeclarationOp::checkName(interface,
|
||||||
eTy->name)) {
|
eTy->name)) {
|
||||||
result.append(QuickFixOperation::Ptr(
|
result.append(new AddIncludeForForwardDeclarationOp(interface, index, fwdClass));
|
||||||
new AddIncludeForForwardDeclarationOp(interface, index, fwdClass)));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1752,8 +1730,7 @@ void AddLocalDeclaration::match(const CppQuickFixInterface &interface, QuickFixO
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!decl) {
|
if (!decl) {
|
||||||
result.append(QuickFixOperation::Ptr(
|
result.append(new AddLocalDeclarationOp(interface, index, binary, nameAST));
|
||||||
new AddLocalDeclarationOp(interface, index, binary, nameAST)));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1829,8 +1806,7 @@ void ConvertToCamelCase::match(const CppQuickFixInterface &interface, QuickFixOp
|
|||||||
return;
|
return;
|
||||||
for (int i = 1; i < newName.length() - 1; ++i) {
|
for (int i = 1; i < newName.length() - 1; ++i) {
|
||||||
if (ConvertToCamelCaseOp::isConvertibleUnderscore(newName, i)) {
|
if (ConvertToCamelCaseOp::isConvertibleUnderscore(newName, i)) {
|
||||||
result.append(QuickFixOperation::Ptr(
|
result.append(new ConvertToCamelCaseOp(interface, path.size() - 1, newName));
|
||||||
new ConvertToCamelCaseOp(interface, path.size() - 1, newName)));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1948,10 +1924,8 @@ void AddIncludeForUndefinedIdentifier::match(const CppQuickFixInterface &interfa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shortestInclude.isEmpty()) {
|
if (!shortestInclude.isEmpty())
|
||||||
result += CppQuickFixOperation::Ptr(
|
result.append(new AddIncludeForUndefinedIdentifierOp(interface, 0, shortestInclude));
|
||||||
new AddIncludeForUndefinedIdentifierOp(interface, 0, shortestInclude));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool isProbablyAQtClass = className.size() > 2
|
const bool isProbablyAQtClass = className.size() > 2
|
||||||
@@ -1964,8 +1938,7 @@ void AddIncludeForUndefinedIdentifier::match(const CppQuickFixInterface &interfa
|
|||||||
// for QSomething, propose a <QSomething> include -- if such a class was in the locator
|
// for QSomething, propose a <QSomething> include -- if such a class was in the locator
|
||||||
if (classExists) {
|
if (classExists) {
|
||||||
const QString include = QLatin1Char('<') + className + QLatin1Char('>');
|
const QString include = QLatin1Char('<') + className + QLatin1Char('>');
|
||||||
result += CppQuickFixOperation::Ptr(
|
result.append(new AddIncludeForUndefinedIdentifierOp(interface, 1, include));
|
||||||
new AddIncludeForUndefinedIdentifierOp(interface, 1, include));
|
|
||||||
|
|
||||||
// otherwise, check for a header file with the same name in the Qt include paths
|
// otherwise, check for a header file with the same name in the Qt include paths
|
||||||
} else {
|
} else {
|
||||||
@@ -1977,8 +1950,7 @@ void AddIncludeForUndefinedIdentifier::match(const CppQuickFixInterface &interfa
|
|||||||
const QFileInfo fileInfo(headerPathCandidate);
|
const QFileInfo fileInfo(headerPathCandidate);
|
||||||
if (fileInfo.exists() && fileInfo.isFile()) {
|
if (fileInfo.exists() && fileInfo.isFile()) {
|
||||||
const QString include = QLatin1Char('<') + className + QLatin1Char('>');
|
const QString include = QLatin1Char('<') + className + QLatin1Char('>');
|
||||||
result += CppQuickFixOperation::Ptr(
|
result.append(new AddIncludeForUndefinedIdentifierOp(interface, 1, include));
|
||||||
new AddIncludeForUndefinedIdentifierOp(interface, 1, include));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2061,13 +2033,11 @@ void RearrangeParamDeclarationList::match(const CppQuickFixInterface &interface,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (prevParamListNode)
|
if (prevParamListNode)
|
||||||
result.append(CppQuickFixOperation::Ptr(
|
result.append(new RearrangeParamDeclarationListOp(interface, paramListNode->value,
|
||||||
new RearrangeParamDeclarationListOp(interface, paramListNode->value,
|
prevParamListNode->value, RearrangeParamDeclarationListOp::TargetPrevious));
|
||||||
prevParamListNode->value, RearrangeParamDeclarationListOp::TargetPrevious)));
|
|
||||||
if (paramListNode->next)
|
if (paramListNode->next)
|
||||||
result.append(CppQuickFixOperation::Ptr(
|
result.append(new RearrangeParamDeclarationListOp(interface, paramListNode->value,
|
||||||
new RearrangeParamDeclarationListOp(interface, paramListNode->value,
|
paramListNode->next->value, RearrangeParamDeclarationListOp::TargetNext));
|
||||||
paramListNode->next->value, RearrangeParamDeclarationListOp::TargetNext)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -2184,18 +2154,15 @@ void ReformatPointerDeclaration::match(const CppQuickFixInterface &interface,
|
|||||||
// ctrl-a and there is an empty line in the end, then the cursor is not on
|
// ctrl-a and there is an empty line in the end, then the cursor is not on
|
||||||
// any AST and therefore no quick fix will be triggered.
|
// any AST and therefore no quick fix will be triggered.
|
||||||
change = formatter.format(file->cppDocument()->translationUnit()->ast());
|
change = formatter.format(file->cppDocument()->translationUnit()->ast());
|
||||||
if (!change.isEmpty()) {
|
if (!change.isEmpty())
|
||||||
result.append(QuickFixOperation::Ptr(
|
result.append(new ReformatPointerDeclarationOp(interface, change));
|
||||||
new ReformatPointerDeclarationOp(interface, change)));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
const QList<AST *> suitableASTs
|
const QList<AST *> suitableASTs
|
||||||
= ReformatPointerDeclarationASTPathResultsFilter().filter(path);
|
= ReformatPointerDeclarationASTPathResultsFilter().filter(path);
|
||||||
foreach (AST *ast, suitableASTs) {
|
foreach (AST *ast, suitableASTs) {
|
||||||
change = formatter.format(ast);
|
change = formatter.format(ast);
|
||||||
if (!change.isEmpty()) {
|
if (!change.isEmpty()) {
|
||||||
result.append(QuickFixOperation::Ptr(
|
result.append(new ReformatPointerDeclarationOp(interface, change));
|
||||||
new ReformatPointerDeclarationOp(interface, change)));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2363,7 +2330,8 @@ void CompleteSwitchCaseStatement::match(const CppQuickFixInterface &interface,
|
|||||||
foreach (const QString &usedValue, usedValues)
|
foreach (const QString &usedValue, usedValues)
|
||||||
values.removeAll(usedValue);
|
values.removeAll(usedValue);
|
||||||
if (!values.isEmpty())
|
if (!values.isEmpty())
|
||||||
result.append(CppQuickFixOperation::Ptr(new CompleteSwitchCaseStatementOp(interface, depth, compoundStatement, values)));
|
result.append(new CompleteSwitchCaseStatementOp(interface, depth,
|
||||||
|
compoundStatement, values));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2441,12 +2409,10 @@ public:
|
|||||||
, m_matchingClass(matchingClass)
|
, m_matchingClass(matchingClass)
|
||||||
, m_decl(decl)
|
, m_decl(decl)
|
||||||
{}
|
{}
|
||||||
TextEditor::QuickFixOperation::Ptr
|
|
||||||
operator()(InsertionPointLocator::AccessSpec xsSpec, int priority)
|
QuickFixOperation *operator()(InsertionPointLocator::AccessSpec xsSpec, int priority)
|
||||||
{
|
{
|
||||||
return TextEditor::QuickFixOperation::Ptr(
|
return new InsertDeclOperation(m_interface, m_fileName, m_matchingClass, xsSpec, m_decl, priority);
|
||||||
new InsertDeclOperation(m_interface, m_fileName, m_matchingClass, xsSpec, m_decl,
|
|
||||||
priority));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -2721,7 +2687,7 @@ void InsertDefFromDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (op)
|
if (op)
|
||||||
result.append(CppQuickFixOperation::Ptr(op));
|
result.append(op);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2731,10 +2697,10 @@ void InsertDefFromDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
|
|||||||
|
|
||||||
// Insert Position: Outside Class
|
// Insert Position: Outside Class
|
||||||
if (!isFreeFunction) {
|
if (!isFreeFunction) {
|
||||||
op = new InsertDefOperation(interface, decl, declAST,
|
result.append(new InsertDefOperation(interface, decl, declAST,
|
||||||
InsertionLocation(), DefPosOutsideClass,
|
InsertionLocation(),
|
||||||
interface->fileName());
|
DefPosOutsideClass,
|
||||||
result.append(CppQuickFixOperation::Ptr(op));
|
interface->fileName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert Position: Inside Class
|
// Insert Position: Inside Class
|
||||||
@@ -2745,10 +2711,9 @@ void InsertDefFromDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
|
|||||||
const InsertionLocation loc
|
const InsertionLocation loc
|
||||||
= InsertionLocation(interface->fileName(), QString(), QString(),
|
= InsertionLocation(interface->fileName(), QString(), QString(),
|
||||||
line, column);
|
line, column);
|
||||||
op = new InsertDefOperation(interface, decl, declAST, loc,
|
result.append(new InsertDefOperation(interface, decl, declAST, loc,
|
||||||
DefPosInsideClass, QString(),
|
DefPosInsideClass, QString(),
|
||||||
isFreeFunction);
|
isFreeFunction));
|
||||||
result.append(CppQuickFixOperation::Ptr(op));
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -3049,7 +3014,7 @@ void GenerateGetterSetter::match(const CppQuickFixInterface &interface, QuickFix
|
|||||||
{
|
{
|
||||||
GenerateGetterSetterOperation *op = new GenerateGetterSetterOperation(interface);
|
GenerateGetterSetterOperation *op = new GenerateGetterSetterOperation(interface);
|
||||||
if (op->isValid())
|
if (op->isValid())
|
||||||
result.append(CppQuickFixOperation::Ptr(op));
|
result.append(op);
|
||||||
else
|
else
|
||||||
delete op;
|
delete op;
|
||||||
}
|
}
|
||||||
@@ -3575,12 +3540,12 @@ void ExtractFunction::match(const CppQuickFixInterface &interface, QuickFixOpera
|
|||||||
// The current implementation doesn't try to be too smart since it preserves the original form
|
// The current implementation doesn't try to be too smart since it preserves the original form
|
||||||
// of the declarations. This might be or not the desired effect. An improvement would be to
|
// of the declarations. This might be or not the desired effect. An improvement would be to
|
||||||
// let the user somehow customize the function interface.
|
// let the user somehow customize the function interface.
|
||||||
result.append(CppQuickFixOperation::Ptr(new ExtractFunctionOperation(interface,
|
result.append(new ExtractFunctionOperation(interface,
|
||||||
analyser.m_extractionStart,
|
analyser.m_extractionStart,
|
||||||
analyser.m_extractionEnd,
|
analyser.m_extractionEnd,
|
||||||
refFuncDef,
|
refFuncDef,
|
||||||
funcReturn,
|
funcReturn,
|
||||||
relevantDecls)));
|
relevantDecls));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -3900,9 +3865,7 @@ void ExtractLiteralAsParameter::match(const CppQuickFixInterface &interface,
|
|||||||
}
|
}
|
||||||
|
|
||||||
const int priority = path.size() - 1;
|
const int priority = path.size() - 1;
|
||||||
QuickFixOperation::Ptr op(
|
result.append(new ExtractLiteralAsParameterOp(interface, priority, literal, function));
|
||||||
new ExtractLiteralAsParameterOp(interface, priority, literal, function));
|
|
||||||
result.append(op);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -4197,10 +4160,8 @@ void ConvertFromAndToPointer::match(const CppQuickFixInterface &interface,
|
|||||||
}
|
}
|
||||||
|
|
||||||
const int priority = path.size() - 1;
|
const int priority = path.size() - 1;
|
||||||
QuickFixOperation::Ptr op(
|
result.append(new ConvertFromAndToPointerOp(interface, priority, mode, simpleDeclaration,
|
||||||
new ConvertFromAndToPointerOp(interface, priority, mode, simpleDeclaration, declarator,
|
declarator, identifier, symbol));
|
||||||
identifier, symbol));
|
|
||||||
result.append(op);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -4379,9 +4340,9 @@ void InsertQtPropertyMembers::match(const CppQuickFixInterface &interface,
|
|||||||
if (getterName.isEmpty() && setterName.isEmpty() && signalName.isEmpty())
|
if (getterName.isEmpty() && setterName.isEmpty() && signalName.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
result.append(QuickFixOperation::Ptr(
|
result.append(new InsertQtPropertyMembersOp(interface, path.size() - 1, qtPropertyDeclaration, c,
|
||||||
new InsertQtPropertyMembersOp(interface, path.size() - 1, qtPropertyDeclaration, c,
|
generateFlags, getterName, setterName,
|
||||||
generateFlags, getterName, setterName, signalName, storageName)));
|
signalName, storageName));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -4420,9 +4381,9 @@ void ApplyDeclDefLinkChanges::match(const CppQuickFixInterface &interface,
|
|||||||
if (!link || !link->isMarkerVisible())
|
if (!link || !link->isMarkerVisible())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QSharedPointer<ApplyDeclDefLinkOperation> op(new ApplyDeclDefLinkOperation(interface, link));
|
auto op = new ApplyDeclDefLinkOperation(interface, link);
|
||||||
op->setDescription(FunctionDeclDefLink::tr("Apply Function Signature Changes"));
|
op->setDescription(FunctionDeclDefLink::tr("Apply Function Signature Changes"));
|
||||||
result += op;
|
result.append(op);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -4589,16 +4550,14 @@ void MoveFuncDefOutside::match(const CppQuickFixInterface &interface, QuickFixOp
|
|||||||
const QString cppFileName = correspondingHeaderOrSource(interface->fileName(), &isHeaderFile);
|
const QString cppFileName = correspondingHeaderOrSource(interface->fileName(), &isHeaderFile);
|
||||||
|
|
||||||
if (isHeaderFile && !cppFileName.isEmpty())
|
if (isHeaderFile && !cppFileName.isEmpty())
|
||||||
result.append(CppQuickFixOperation::Ptr(
|
result.append(new MoveFuncDefOutsideOp(interface, ((moveOutsideMemberDefinition) ?
|
||||||
new MoveFuncDefOutsideOp(interface, ((moveOutsideMemberDefinition) ?
|
|
||||||
MoveFuncDefOutsideOp::MoveOutsideMemberToCppFile
|
MoveFuncDefOutsideOp::MoveOutsideMemberToCppFile
|
||||||
: MoveFuncDefOutsideOp::MoveToCppFile),
|
: MoveFuncDefOutsideOp::MoveToCppFile),
|
||||||
funcAST, cppFileName)));
|
funcAST, cppFileName));
|
||||||
|
|
||||||
if (classAST)
|
if (classAST)
|
||||||
result.append(CppQuickFixOperation::Ptr(
|
result.append(new MoveFuncDefOutsideOp(interface, MoveFuncDefOutsideOp::MoveOutside,
|
||||||
new MoveFuncDefOutsideOp(interface, MoveFuncDefOutsideOp::MoveOutside,
|
funcAST, QLatin1String("")));
|
||||||
funcAST, QLatin1String(""))));
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -4766,11 +4725,11 @@ void MoveFuncDefToDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!declFileName.isEmpty() && !declText.isEmpty())
|
if (!declFileName.isEmpty() && !declText.isEmpty())
|
||||||
result.append(QuickFixOperation::Ptr(new MoveFuncDefToDeclOp(interface,
|
result.append(new MoveFuncDefToDeclOp(interface,
|
||||||
interface->fileName(),
|
interface->fileName(),
|
||||||
declFileName,
|
declFileName,
|
||||||
funcAST, declText,
|
funcAST, declText,
|
||||||
declRange)));
|
declRange));
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -4977,9 +4936,7 @@ void AssignToLocalVariable::match(const CppQuickFixInterface &interface, QuickFi
|
|||||||
|
|
||||||
const Name *name = visibleNameAST->name;
|
const Name *name = visibleNameAST->name;
|
||||||
const int insertPos = interface->currentFile()->startOf(outerAST);
|
const int insertPos = interface->currentFile()->startOf(outerAST);
|
||||||
result.append(CppQuickFixOperation::Ptr(
|
result.append(new AssignToLocalVariableOperation(interface, insertPos, outerAST, name));
|
||||||
new AssignToLocalVariableOperation(interface, insertPos, outerAST,
|
|
||||||
name)));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5160,11 +5117,9 @@ void OptimizeForLoop::match(const CppQuickFixInterface &interface, QuickFixOpera
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (optimizePostcrement || optimizeCondition) {
|
if (optimizePostcrement || optimizeCondition) {
|
||||||
OptimizeForLoopOperation *op
|
result.append(new OptimizeForLoopOperation(interface, forAst, optimizePostcrement,
|
||||||
= new OptimizeForLoopOperation(interface, forAst, optimizePostcrement,
|
|
||||||
(optimizeCondition) ? conditionExpression : 0,
|
(optimizeCondition) ? conditionExpression : 0,
|
||||||
conditionType);
|
conditionType));
|
||||||
result.append(QuickFixOperation::Ptr(op));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5328,17 +5283,11 @@ void EscapeStringLiteral::match(const CppQuickFixInterface &interface, QuickFixO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canEscape) {
|
if (canEscape)
|
||||||
QuickFixOperation::Ptr op(
|
result.append(new EscapeStringLiteralOperation(interface, literal, true));
|
||||||
new EscapeStringLiteralOperation(interface, literal, true));
|
|
||||||
result.append(op);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (canUnescape) {
|
if (canUnescape)
|
||||||
QuickFixOperation::Ptr op(
|
result.append(new EscapeStringLiteralOperation(interface, literal, false));
|
||||||
new EscapeStringLiteralOperation(interface, literal, false));
|
|
||||||
result.append(op);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -176,13 +176,13 @@ void ComponentFromObjectDef::match(const QmlJSQuickFixInterface &interface, Quic
|
|||||||
return;
|
return;
|
||||||
// check that the node is not the root node
|
// check that the node is not the root node
|
||||||
if (i > 0 && !cast<UiProgram*>(path.at(i - 1))) {
|
if (i > 0 && !cast<UiProgram*>(path.at(i - 1))) {
|
||||||
result.append(QuickFixOperation::Ptr(new Operation(interface, objDef)));
|
result.append(new Operation(interface, objDef));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (UiObjectBinding *objBinding = cast<UiObjectBinding *>(node)) {
|
} else if (UiObjectBinding *objBinding = cast<UiObjectBinding *>(node)) {
|
||||||
if (!interface->currentFile()->isCursorOn(objBinding->qualifiedTypeNameId))
|
if (!interface->currentFile()->isCursorOn(objBinding->qualifiedTypeNameId))
|
||||||
return;
|
return;
|
||||||
result.append(QuickFixOperation::Ptr(new Operation(interface, objBinding)));
|
result.append(new Operation(interface, objBinding));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -665,8 +665,7 @@ void QmlJSEditorWidget::showContextPane()
|
|||||||
|
|
||||||
void QmlJSEditorWidget::performQuickFix(int index)
|
void QmlJSEditorWidget::performQuickFix(int index)
|
||||||
{
|
{
|
||||||
QuickFixOperation::Ptr op = m_quickFixes.at(index);
|
m_quickFixes.at(index)->perform();
|
||||||
op->perform();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QmlJSEditorWidget::contextMenuEvent(QContextMenuEvent *e)
|
void QmlJSEditorWidget::contextMenuEvent(QContextMenuEvent *e)
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ private:
|
|||||||
QModelIndex m_outlineModelIndex;
|
QModelIndex m_outlineModelIndex;
|
||||||
QmlJS::ModelManagerInterface *m_modelManager;
|
QmlJS::ModelManagerInterface *m_modelManager;
|
||||||
|
|
||||||
QList<TextEditor::QuickFixOperation::Ptr> m_quickFixes;
|
TextEditor::QuickFixOperations m_quickFixes;
|
||||||
|
|
||||||
QmlJS::IContextPane *m_contextPane;
|
QmlJS::IContextPane *m_contextPane;
|
||||||
int m_oldCursorPosition;
|
int m_oldCursorPosition;
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ class SplitInitializerOp: public QmlJSQuickFixFactory
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (objectInitializer)
|
if (objectInitializer)
|
||||||
result.append(TextEditor::QuickFixOperation::Ptr(new Operation(interface, objectInitializer)));
|
result.append(new Operation(interface, objectInitializer));
|
||||||
}
|
}
|
||||||
|
|
||||||
class Operation: public QmlJSQuickFixOperation
|
class Operation: public QmlJSQuickFixOperation
|
||||||
@@ -139,7 +139,7 @@ public:
|
|||||||
|
|
||||||
foreach (const StaticAnalysis::Message &message, messages) {
|
foreach (const StaticAnalysis::Message &message, messages) {
|
||||||
if (interface->currentFile()->isCursorOn(message.location)) {
|
if (interface->currentFile()->isCursorOn(message.location)) {
|
||||||
result.append(QuickFixOperation::Ptr(new Operation(interface, message)));
|
result.append(new Operation(interface, message));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -189,13 +189,13 @@ void WrapInLoader::match(const QmlJSQuickFixInterface &interface, QuickFixOperat
|
|||||||
return;
|
return;
|
||||||
// check that the node is not the root node
|
// check that the node is not the root node
|
||||||
if (i > 0 && !cast<UiProgram*>(path.at(i - 1))) {
|
if (i > 0 && !cast<UiProgram*>(path.at(i - 1))) {
|
||||||
result.append(QuickFixOperation::Ptr(new Operation<UiObjectDefinition>(interface, objDef)));
|
result.append(new Operation<UiObjectDefinition>(interface, objDef));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (UiObjectBinding *objBinding = cast<UiObjectBinding *>(node)) {
|
} else if (UiObjectBinding *objBinding = cast<UiObjectBinding *>(node)) {
|
||||||
if (!interface->currentFile()->isCursorOn(objBinding->qualifiedTypeNameId))
|
if (!interface->currentFile()->isCursorOn(objBinding->qualifiedTypeNameId))
|
||||||
return;
|
return;
|
||||||
result.append(QuickFixOperation::Ptr(new Operation<UiObjectBinding>(interface, objBinding)));
|
result.append(new Operation<UiObjectBinding>(interface, objBinding));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,7 +90,13 @@ private:
|
|||||||
QString _description;
|
QString _description;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef QList<QuickFixOperation::Ptr> QuickFixOperations;
|
class TEXTEDITOR_EXPORT QuickFixOperations : public QList<QuickFixOperation::Ptr>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using QList<QuickFixOperation::Ptr>::append;
|
||||||
|
void append(QuickFixOperation *op) { append(QuickFixOperation::Ptr(op)); }
|
||||||
|
};
|
||||||
|
|
||||||
typedef QSharedPointer<const AssistInterface> QuickFixInterface;
|
typedef QSharedPointer<const AssistInterface> QuickFixInterface;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
Reference in New Issue
Block a user