2011-08-10 09:50:04 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
|
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
|
**
|
|
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
|
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
|
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
|
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
|
** Nokia at info@qt.nokia.com.
|
|
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "cppfunctiondecldeflink.h"
|
|
|
|
|
|
|
|
|
|
#include "cppeditor.h"
|
2011-09-05 10:33:17 +02:00
|
|
|
#include "cppquickfixassistant.h"
|
2011-08-10 09:50:04 +02:00
|
|
|
|
|
|
|
|
#include <cplusplus/CppRewriter.h>
|
|
|
|
|
#include <cplusplus/ASTPath.h>
|
|
|
|
|
#include <cplusplus/AST.h>
|
|
|
|
|
#include <cplusplus/Symbols.h>
|
|
|
|
|
#include <cplusplus/TypeOfExpression.h>
|
|
|
|
|
#include <cplusplus/TranslationUnit.h>
|
|
|
|
|
#include <cplusplus/LookupContext.h>
|
|
|
|
|
#include <cplusplus/Overview.h>
|
2011-08-17 11:35:57 +02:00
|
|
|
#include <cpptools/cpprefactoringchanges.h>
|
2011-08-10 09:50:04 +02:00
|
|
|
#include <texteditor/refactoroverlay.h>
|
|
|
|
|
#include <texteditor/tooltip/tooltip.h>
|
|
|
|
|
#include <texteditor/tooltip/tipcontents.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
2011-09-13 11:07:37 +02:00
|
|
|
#include <utils/proxyaction.h>
|
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <texteditor/texteditorconstants.h>
|
2011-08-10 09:50:04 +02:00
|
|
|
|
|
|
|
|
#include <QtCore/QtConcurrentRun>
|
|
|
|
|
|
|
|
|
|
using namespace CPlusPlus;
|
|
|
|
|
using namespace CppEditor;
|
|
|
|
|
using namespace CppEditor::Internal;
|
|
|
|
|
|
|
|
|
|
FunctionDeclDefLinkFinder::FunctionDeclDefLinkFinder(QObject *parent)
|
|
|
|
|
: QObject(parent)
|
|
|
|
|
{
|
|
|
|
|
connect(&m_watcher, SIGNAL(finished()),
|
|
|
|
|
this, SLOT(onFutureDone()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FunctionDeclDefLinkFinder::onFutureDone()
|
|
|
|
|
{
|
|
|
|
|
QSharedPointer<FunctionDeclDefLink> link = m_watcher.result();
|
2011-08-25 13:22:21 +02:00
|
|
|
if (link) {
|
2011-08-10 09:50:04 +02:00
|
|
|
link->linkSelection = m_scannedSelection;
|
2011-08-25 13:22:21 +02:00
|
|
|
link->nameSelection = m_nameSelection;
|
|
|
|
|
if (m_nameSelection.selectedText() != link->nameInitial)
|
|
|
|
|
link.clear();
|
|
|
|
|
}
|
2011-08-10 09:50:04 +02:00
|
|
|
m_scannedSelection = QTextCursor();
|
2011-08-25 13:22:21 +02:00
|
|
|
m_nameSelection = QTextCursor();
|
2011-08-10 09:50:04 +02:00
|
|
|
if (link)
|
|
|
|
|
emit foundLink(link);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTextCursor FunctionDeclDefLinkFinder::scannedSelection() const
|
|
|
|
|
{
|
|
|
|
|
return m_scannedSelection;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// parent is either a FunctionDefinitionAST or a SimpleDeclarationAST
|
2011-08-17 11:35:57 +02:00
|
|
|
// line and column are 1-based
|
|
|
|
|
static bool findDeclOrDef(const Document::Ptr &doc, int line, int column,
|
2011-08-25 13:22:21 +02:00
|
|
|
DeclarationAST **parent, DeclaratorAST **decl,
|
|
|
|
|
FunctionDeclaratorAST **funcDecl)
|
2011-08-10 09:50:04 +02:00
|
|
|
{
|
2011-08-17 11:35:57 +02:00
|
|
|
QList<AST *> path = ASTPath(doc)(line, column);
|
2011-08-10 09:50:04 +02:00
|
|
|
|
|
|
|
|
// for function definitions, simply scan for FunctionDefinitionAST not preceded
|
|
|
|
|
// by CompoundStatement/CtorInitializer
|
|
|
|
|
// for function declarations, look for SimpleDeclarations with a single Declarator
|
|
|
|
|
// with a FunctionDeclarator postfix
|
|
|
|
|
FunctionDefinitionAST *funcDef = 0;
|
|
|
|
|
SimpleDeclarationAST *simpleDecl = 0;
|
2011-08-25 13:22:21 +02:00
|
|
|
*decl = 0;
|
2011-08-10 09:50:04 +02:00
|
|
|
for (int i = path.size() - 1; i > 0; --i) {
|
|
|
|
|
AST *ast = path.at(i);
|
|
|
|
|
if (ast->asCompoundStatement() || ast->asCtorInitializer())
|
|
|
|
|
break;
|
|
|
|
|
if ((funcDef = ast->asFunctionDefinition()) != 0) {
|
|
|
|
|
*parent = funcDef;
|
2011-08-25 13:22:21 +02:00
|
|
|
*decl = funcDef->declarator;
|
2011-08-10 09:50:04 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if ((simpleDecl = ast->asSimpleDeclaration()) != 0) {
|
|
|
|
|
*parent = simpleDecl;
|
|
|
|
|
if (!simpleDecl->declarator_list || !simpleDecl->declarator_list->value)
|
|
|
|
|
break;
|
2011-08-25 13:22:21 +02:00
|
|
|
*decl = simpleDecl->declarator_list->value;
|
2011-08-10 09:50:04 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-08-25 13:22:21 +02:00
|
|
|
if (!*parent || !*decl)
|
2011-08-10 09:50:04 +02:00
|
|
|
return false;
|
2011-08-25 13:22:21 +02:00
|
|
|
if (!(*decl)->postfix_declarator_list || !(*decl)->postfix_declarator_list->value)
|
2011-08-10 09:50:04 +02:00
|
|
|
return false;
|
2011-08-25 13:22:21 +02:00
|
|
|
*funcDecl = (*decl)->postfix_declarator_list->value->asFunctionDeclarator();
|
2011-08-10 09:50:04 +02:00
|
|
|
return *funcDecl;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 11:35:57 +02:00
|
|
|
static void declDefLinkStartEnd(const CppTools::CppRefactoringFileConstPtr &file,
|
2011-08-10 09:50:04 +02:00
|
|
|
DeclarationAST *parent, FunctionDeclaratorAST *funcDecl,
|
|
|
|
|
int *start, int *end)
|
|
|
|
|
{
|
2011-08-17 11:35:57 +02:00
|
|
|
*start = file->startOf(parent);
|
2011-08-10 09:50:04 +02:00
|
|
|
if (funcDecl->trailing_return_type)
|
2011-08-17 11:35:57 +02:00
|
|
|
*end = file->endOf(funcDecl->trailing_return_type);
|
2011-08-10 09:50:04 +02:00
|
|
|
else if (funcDecl->exception_specification)
|
2011-08-17 11:35:57 +02:00
|
|
|
*end = file->endOf(funcDecl->exception_specification);
|
2011-08-10 09:50:04 +02:00
|
|
|
else if (funcDecl->cv_qualifier_list)
|
2011-08-17 11:35:57 +02:00
|
|
|
*end = file->endOf(funcDecl->cv_qualifier_list->lastValue());
|
2011-08-10 09:50:04 +02:00
|
|
|
else
|
2011-08-17 11:35:57 +02:00
|
|
|
*end = file->endOf(funcDecl->rparen_token);
|
2011-08-10 09:50:04 +02:00
|
|
|
}
|
|
|
|
|
|
2011-08-25 13:22:21 +02:00
|
|
|
static DeclaratorIdAST *getDeclaratorId(DeclaratorAST *declarator)
|
|
|
|
|
{
|
|
|
|
|
if (!declarator || !declarator->core_declarator)
|
|
|
|
|
return 0;
|
|
|
|
|
if (DeclaratorIdAST *id = declarator->core_declarator->asDeclaratorId()) {
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
if (NestedDeclaratorAST *nested = declarator->core_declarator->asNestedDeclarator()) {
|
|
|
|
|
return getDeclaratorId(nested->declarator);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-10 09:50:04 +02:00
|
|
|
static QSharedPointer<FunctionDeclDefLink> findLinkHelper(QSharedPointer<FunctionDeclDefLink> link, CppTools::CppRefactoringChanges changes)
|
|
|
|
|
{
|
|
|
|
|
QSharedPointer<FunctionDeclDefLink> noResult;
|
|
|
|
|
const Snapshot &snapshot = changes.snapshot();
|
|
|
|
|
|
|
|
|
|
// find the matching decl/def symbol
|
|
|
|
|
Symbol *target = 0;
|
|
|
|
|
if (FunctionDefinitionAST *funcDef = link->sourceDeclaration->asFunctionDefinition()) {
|
|
|
|
|
QList<Declaration *> nameMatch, argumentCountMatch, typeMatch;
|
|
|
|
|
findMatchingDeclaration(LookupContext(link->sourceDocument, snapshot),
|
|
|
|
|
funcDef->symbol,
|
|
|
|
|
&typeMatch, &argumentCountMatch, &nameMatch);
|
|
|
|
|
if (!typeMatch.isEmpty())
|
|
|
|
|
target = typeMatch.first();
|
|
|
|
|
} else if (link->sourceDeclaration->asSimpleDeclaration()) {
|
|
|
|
|
target = snapshot.findMatchingDefinition(link->sourceFunctionDeclarator->symbol, true);
|
|
|
|
|
}
|
|
|
|
|
if (!target) {
|
|
|
|
|
return noResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// parse the target file to get the linked decl/def
|
|
|
|
|
const QString targetFileName = QString::fromUtf8(
|
|
|
|
|
target->fileName(), target->fileNameLength());
|
2011-08-17 11:35:57 +02:00
|
|
|
CppTools::CppRefactoringFileConstPtr targetFile = changes.fileNoEditor(targetFileName);
|
|
|
|
|
if (!targetFile->isValid())
|
2011-08-10 09:50:04 +02:00
|
|
|
return noResult;
|
|
|
|
|
|
|
|
|
|
DeclarationAST *targetParent = 0;
|
|
|
|
|
FunctionDeclaratorAST *targetFuncDecl = 0;
|
2011-08-25 13:22:21 +02:00
|
|
|
DeclaratorAST *targetDeclarator = 0;
|
2011-08-17 11:35:57 +02:00
|
|
|
if (!findDeclOrDef(targetFile->cppDocument(), target->line(), target->column(),
|
2011-08-25 13:22:21 +02:00
|
|
|
&targetParent, &targetDeclarator, &targetFuncDecl))
|
2011-08-10 09:50:04 +02:00
|
|
|
return noResult;
|
|
|
|
|
|
|
|
|
|
// the parens are necessary for finding good places for changes
|
|
|
|
|
if (!targetFuncDecl->lparen_token || !targetFuncDecl->rparen_token)
|
|
|
|
|
return noResult;
|
|
|
|
|
|
|
|
|
|
int targetStart, targetEnd;
|
|
|
|
|
declDefLinkStartEnd(targetFile, targetParent, targetFuncDecl, &targetStart, &targetEnd);
|
2011-08-17 11:35:57 +02:00
|
|
|
QString targetInitial = targetFile->textOf(
|
|
|
|
|
targetFile->startOf(targetParent),
|
2011-08-10 09:50:04 +02:00
|
|
|
targetEnd);
|
|
|
|
|
|
2011-08-17 14:11:35 +02:00
|
|
|
targetFile->lineAndColumn(targetStart, &link->targetLine, &link->targetColumn);
|
2011-08-10 09:50:04 +02:00
|
|
|
link->targetInitial = targetInitial;
|
|
|
|
|
|
2011-08-17 11:35:57 +02:00
|
|
|
link->targetFile = targetFile;
|
2011-08-10 09:50:04 +02:00
|
|
|
link->targetFunction = targetFuncDecl->symbol;
|
|
|
|
|
link->targetFunctionDeclarator = targetFuncDecl;
|
|
|
|
|
link->targetDeclaration = targetParent;
|
|
|
|
|
|
|
|
|
|
return link;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FunctionDeclDefLinkFinder::startFindLinkAt(
|
|
|
|
|
QTextCursor cursor, const Document::Ptr &doc, const Snapshot &snapshot)
|
|
|
|
|
{
|
|
|
|
|
// check if cursor is on function decl/def
|
|
|
|
|
DeclarationAST *parent = 0;
|
|
|
|
|
FunctionDeclaratorAST *funcDecl = 0;
|
2011-08-25 13:22:21 +02:00
|
|
|
DeclaratorAST *declarator = 0;
|
|
|
|
|
if (!findDeclOrDef(doc, cursor.blockNumber() + 1, cursor.columnNumber() + 1,
|
|
|
|
|
&parent, &declarator, &funcDecl))
|
2011-08-10 09:50:04 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// find the start/end offsets
|
|
|
|
|
CppTools::CppRefactoringChanges refactoringChanges(snapshot);
|
2011-08-17 11:35:57 +02:00
|
|
|
CppTools::CppRefactoringFilePtr sourceFile = refactoringChanges.file(doc->fileName());
|
|
|
|
|
sourceFile->setCppDocument(doc);
|
2011-08-10 09:50:04 +02:00
|
|
|
int start, end;
|
|
|
|
|
declDefLinkStartEnd(sourceFile, parent, funcDecl, &start, &end);
|
|
|
|
|
|
|
|
|
|
// if already scanning, don't scan again
|
|
|
|
|
if (!m_scannedSelection.isNull()
|
|
|
|
|
&& m_scannedSelection.selectionStart() == start
|
|
|
|
|
&& m_scannedSelection.selectionEnd() == end) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// build the selection for the currently scanned area
|
|
|
|
|
m_scannedSelection = cursor;
|
|
|
|
|
m_scannedSelection.setPosition(end);
|
|
|
|
|
m_scannedSelection.setPosition(start, QTextCursor::KeepAnchor);
|
|
|
|
|
m_scannedSelection.setKeepPositionOnInsert(true);
|
|
|
|
|
|
2011-08-25 13:22:21 +02:00
|
|
|
// build selection for the name
|
|
|
|
|
DeclaratorIdAST *declId = getDeclaratorId(declarator);
|
|
|
|
|
m_nameSelection = cursor;
|
|
|
|
|
m_nameSelection.setPosition(sourceFile->endOf(declId));
|
|
|
|
|
m_nameSelection.setPosition(sourceFile->startOf(declId), QTextCursor::KeepAnchor);
|
|
|
|
|
m_nameSelection.setKeepPositionOnInsert(true);
|
|
|
|
|
|
2011-08-10 09:50:04 +02:00
|
|
|
// set up a base result
|
|
|
|
|
QSharedPointer<FunctionDeclDefLink> result(new FunctionDeclDefLink);
|
2011-08-25 13:22:21 +02:00
|
|
|
result->nameInitial = m_nameSelection.selectedText();
|
2011-08-10 09:50:04 +02:00
|
|
|
result->sourceDocument = doc;
|
|
|
|
|
result->sourceFunction = funcDecl->symbol;
|
|
|
|
|
result->sourceDeclaration = parent;
|
|
|
|
|
result->sourceFunctionDeclarator = funcDecl;
|
|
|
|
|
|
|
|
|
|
// handle the rest in a thread
|
|
|
|
|
m_watcher.setFuture(QtConcurrent::run(&findLinkHelper, result, refactoringChanges));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FunctionDeclDefLink::FunctionDeclDefLink()
|
|
|
|
|
{
|
|
|
|
|
hasMarker = false;
|
2011-08-17 14:11:35 +02:00
|
|
|
targetLine = 0;
|
|
|
|
|
targetColumn = 0;
|
2011-08-10 09:50:04 +02:00
|
|
|
sourceFunction = 0;
|
|
|
|
|
targetFunction = 0;
|
|
|
|
|
targetDeclaration = 0;
|
|
|
|
|
targetFunctionDeclarator = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FunctionDeclDefLink::~FunctionDeclDefLink()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FunctionDeclDefLink::isValid() const
|
|
|
|
|
{
|
2011-08-17 11:35:57 +02:00
|
|
|
return !linkSelection.isNull();
|
2011-08-10 09:50:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FunctionDeclDefLink::isMarkerVisible() const
|
|
|
|
|
{
|
|
|
|
|
return hasMarker;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool namesEqual(const Name *n1, const Name *n2)
|
|
|
|
|
{
|
|
|
|
|
return n1 == n2 || (n1 && n2 && n1->isEqualTo(n2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FunctionDeclDefLink::apply(CPPEditorWidget *editor, bool jumpToMatch)
|
|
|
|
|
{
|
|
|
|
|
Snapshot snapshot = editor->semanticInfo().snapshot;
|
|
|
|
|
|
|
|
|
|
// first verify the interesting region of the target file is unchanged
|
|
|
|
|
CppTools::CppRefactoringChanges refactoringChanges(snapshot);
|
2011-08-17 11:35:57 +02:00
|
|
|
CppTools::CppRefactoringFilePtr newTargetFile = refactoringChanges.file(targetFile->fileName());
|
|
|
|
|
if (!newTargetFile->isValid())
|
2011-08-10 09:50:04 +02:00
|
|
|
return;
|
2011-08-17 14:11:35 +02:00
|
|
|
const int targetStart = newTargetFile->position(targetLine, targetColumn);
|
|
|
|
|
const int targetEnd = targetStart + targetInitial.size();
|
|
|
|
|
if (targetInitial == newTargetFile->textOf(targetStart, targetEnd)) {
|
|
|
|
|
const Utils::ChangeSet changeset = changes(snapshot, targetStart);
|
2011-08-17 11:35:57 +02:00
|
|
|
newTargetFile->setChangeSet(changeset);
|
2011-09-05 12:03:47 +02:00
|
|
|
if (jumpToMatch) {
|
|
|
|
|
const int jumpTarget = newTargetFile->position(targetFunction->line(), targetFunction->column());
|
|
|
|
|
newTargetFile->setOpenEditor(true, jumpTarget);
|
|
|
|
|
}
|
2011-08-17 11:35:57 +02:00
|
|
|
newTargetFile->apply();
|
2011-08-10 09:50:04 +02:00
|
|
|
} else {
|
|
|
|
|
TextEditor::ToolTip::instance()->show(
|
|
|
|
|
editor->toolTipPosition(linkSelection),
|
|
|
|
|
TextEditor::TextContent(
|
|
|
|
|
tr("Target file was changed, could not apply changes")));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
|
static QList<TextEditor::RefactorMarker> removeMarkersOfType(const QList<TextEditor::RefactorMarker> &markers)
|
|
|
|
|
{
|
|
|
|
|
QList<TextEditor::RefactorMarker> result;
|
|
|
|
|
foreach (const TextEditor::RefactorMarker &marker, markers) {
|
|
|
|
|
if (!marker.data.canConvert<T>())
|
|
|
|
|
result += marker;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FunctionDeclDefLink::hideMarker(CPPEditorWidget *editor)
|
|
|
|
|
{
|
|
|
|
|
if (!hasMarker)
|
|
|
|
|
return;
|
|
|
|
|
editor->setRefactorMarkers(
|
|
|
|
|
removeMarkersOfType<Marker>(editor->refactorMarkers()));
|
|
|
|
|
hasMarker = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FunctionDeclDefLink::showMarker(CPPEditorWidget *editor)
|
|
|
|
|
{
|
|
|
|
|
if (hasMarker)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QList<TextEditor::RefactorMarker> markers = removeMarkersOfType<Marker>(editor->refactorMarkers());
|
|
|
|
|
TextEditor::RefactorMarker marker;
|
|
|
|
|
|
|
|
|
|
// show the marker at the end of the linked area, with a special case
|
|
|
|
|
// to avoid it overlapping with a trailing semicolon
|
|
|
|
|
marker.cursor = editor->textCursor();
|
|
|
|
|
marker.cursor.setPosition(linkSelection.selectionEnd());
|
|
|
|
|
const int endBlockNr = marker.cursor.blockNumber();
|
|
|
|
|
marker.cursor.setPosition(linkSelection.selectionEnd() + 1, QTextCursor::KeepAnchor);
|
|
|
|
|
if (marker.cursor.blockNumber() != endBlockNr
|
|
|
|
|
|| marker.cursor.selectedText() != QLatin1String(";")) {
|
|
|
|
|
marker.cursor.setPosition(linkSelection.selectionEnd());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString message;
|
|
|
|
|
if (targetDeclaration->asFunctionDefinition())
|
|
|
|
|
message = tr("Apply changes to definition");
|
|
|
|
|
else
|
|
|
|
|
message = tr("Apply changes to declaration");
|
2011-09-13 11:07:37 +02:00
|
|
|
|
|
|
|
|
Core::ActionManager *actionManager = Core::ICore::instance()->actionManager();
|
|
|
|
|
Core::Command *quickfixCommand = actionManager->command(TextEditor::Constants::QUICKFIX_THIS);
|
|
|
|
|
if (quickfixCommand)
|
|
|
|
|
message = Utils::ProxyAction::stringWithAppendedShortcut(message, quickfixCommand->keySequence());
|
|
|
|
|
|
2011-08-10 09:50:04 +02:00
|
|
|
marker.tooltip = message;
|
|
|
|
|
marker.data = QVariant::fromValue(Marker());
|
|
|
|
|
markers += marker;
|
|
|
|
|
editor->setRefactorMarkers(markers);
|
|
|
|
|
|
|
|
|
|
hasMarker = true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-16 14:31:15 +02:00
|
|
|
// does consider foo(void) to have one argument
|
|
|
|
|
static int declaredArgumentCount(Function *function)
|
|
|
|
|
{
|
|
|
|
|
int c = function->memberCount();
|
|
|
|
|
if (c > 0 && function->memberAt(c - 1)->isBlock())
|
|
|
|
|
return c - 1;
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-26 13:11:12 +02:00
|
|
|
Q_GLOBAL_STATIC(QRegExp, commentArgNameRegexp)
|
|
|
|
|
|
|
|
|
|
static bool hasCommentedName(
|
|
|
|
|
TranslationUnit *unit,
|
|
|
|
|
const QString &source,
|
|
|
|
|
FunctionDeclaratorAST *declarator,
|
|
|
|
|
int i)
|
|
|
|
|
{
|
|
|
|
|
if (!declarator
|
|
|
|
|
|| !declarator->parameter_declaration_clause
|
|
|
|
|
|| !declarator->parameter_declaration_clause->parameter_declaration_list)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (Function *f = declarator->symbol) {
|
|
|
|
|
if (Symbol *a = f->argumentAt(i)) {
|
|
|
|
|
if (a->name())
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ParameterDeclarationListAST *list = declarator->parameter_declaration_clause->parameter_declaration_list;
|
|
|
|
|
while (list && i) {
|
|
|
|
|
list = list->next;
|
|
|
|
|
--i;
|
|
|
|
|
}
|
|
|
|
|
if (!list || !list->value || i)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
ParameterDeclarationAST *param = list->value;
|
|
|
|
|
if (param->symbol && param->symbol->name()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// maybe in a comment but in the right spot?
|
|
|
|
|
int nameStart = 0;
|
|
|
|
|
if (param->declarator)
|
|
|
|
|
nameStart = unit->tokenAt(param->declarator->lastToken() - 1).end();
|
|
|
|
|
else if (param->type_specifier_list)
|
|
|
|
|
nameStart = unit->tokenAt(param->type_specifier_list->lastToken() - 1).end();
|
|
|
|
|
else
|
|
|
|
|
nameStart = unit->tokenAt(param->firstToken()).begin();
|
|
|
|
|
|
|
|
|
|
int nameEnd = 0;
|
|
|
|
|
if (param->equal_token)
|
|
|
|
|
nameEnd = unit->tokenAt(param->equal_token).begin();
|
|
|
|
|
else
|
|
|
|
|
nameEnd = unit->tokenAt(param->lastToken()).begin(); // one token after
|
|
|
|
|
|
|
|
|
|
QString text = source.mid(nameStart, nameEnd - nameStart);
|
|
|
|
|
|
|
|
|
|
if (commentArgNameRegexp()->isEmpty()) {
|
|
|
|
|
*commentArgNameRegexp() = QRegExp(QLatin1String("/\\*\\s*(\\w*)\\s*\\*/"));
|
|
|
|
|
}
|
|
|
|
|
return commentArgNameRegexp()->indexIn(text) != -1;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-09 14:21:31 +02:00
|
|
|
static bool canReplaceSpecifier(TranslationUnit *translationUnit, SpecifierAST *specifier)
|
|
|
|
|
{
|
|
|
|
|
if (SimpleSpecifierAST *simple = specifier->asSimpleSpecifier()) {
|
|
|
|
|
switch (translationUnit->tokenAt(simple->specifier_token).kind()) {
|
|
|
|
|
case T_CONST:
|
|
|
|
|
case T_VOLATILE:
|
|
|
|
|
case T_CHAR:
|
|
|
|
|
case T_WCHAR_T:
|
|
|
|
|
case T_BOOL:
|
|
|
|
|
case T_SHORT:
|
|
|
|
|
case T_INT:
|
|
|
|
|
case T_LONG:
|
|
|
|
|
case T_SIGNED:
|
|
|
|
|
case T_UNSIGNED:
|
|
|
|
|
case T_FLOAT:
|
|
|
|
|
case T_DOUBLE:
|
|
|
|
|
case T_VOID:
|
|
|
|
|
case T_AUTO:
|
|
|
|
|
case T___TYPEOF__:
|
|
|
|
|
case T___ATTRIBUTE__:
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-09-13 11:36:05 +02:00
|
|
|
if (specifier->asAttributeSpecifier())
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
2011-09-09 14:21:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpecifierAST *findFirstReplaceableSpecifier(TranslationUnit *translationUnit, SpecifierListAST *list)
|
|
|
|
|
{
|
|
|
|
|
for (SpecifierListAST *it = list; it; it = it->next) {
|
|
|
|
|
if (canReplaceSpecifier(translationUnit, it->value))
|
|
|
|
|
return it->value;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 14:11:35 +02:00
|
|
|
Utils::ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot, int targetOffset)
|
2011-08-10 09:50:04 +02:00
|
|
|
{
|
|
|
|
|
Utils::ChangeSet changes;
|
|
|
|
|
|
|
|
|
|
// parse the current source declaration
|
|
|
|
|
TypeOfExpression typeOfExpression; // ### just need to preprocess...
|
|
|
|
|
typeOfExpression.init(sourceDocument, snapshot);
|
2011-09-08 14:47:19 +02:00
|
|
|
|
|
|
|
|
QString newDeclText = linkSelection.selectedText();
|
|
|
|
|
for (int i = 0; i < newDeclText.size(); ++i) {
|
|
|
|
|
if (newDeclText.at(i).toAscii() == 0)
|
|
|
|
|
newDeclText[i] = QLatin1Char('\n');
|
|
|
|
|
}
|
|
|
|
|
newDeclText.append(QLatin1String("{}"));
|
|
|
|
|
const QString newDeclTextPreprocessed = typeOfExpression.preprocess(newDeclText);
|
|
|
|
|
|
2011-08-10 09:50:04 +02:00
|
|
|
Document::Ptr newDeclDoc = Document::create(QLatin1String("<decl>"));
|
2011-09-08 14:47:19 +02:00
|
|
|
newDeclDoc->setSource(newDeclTextPreprocessed.toUtf8());
|
2011-08-10 09:50:04 +02:00
|
|
|
newDeclDoc->parse(Document::ParseDeclaration);
|
|
|
|
|
newDeclDoc->check();
|
|
|
|
|
|
|
|
|
|
// extract the function symbol
|
2011-08-25 14:55:52 +02:00
|
|
|
if (!newDeclDoc->translationUnit()->ast())
|
2011-08-10 09:50:04 +02:00
|
|
|
return changes;
|
|
|
|
|
FunctionDefinitionAST *newDef = newDeclDoc->translationUnit()->ast()->asFunctionDefinition();
|
2011-08-25 14:55:52 +02:00
|
|
|
if (!newDef)
|
2011-08-10 09:50:04 +02:00
|
|
|
return changes;
|
|
|
|
|
Function *newFunction = newDef->symbol;
|
2011-08-25 14:55:52 +02:00
|
|
|
if (!newFunction)
|
|
|
|
|
return changes;
|
2011-08-10 09:50:04 +02:00
|
|
|
|
2011-09-14 10:42:23 +02:00
|
|
|
LookupContext sourceContext(sourceDocument, snapshot);
|
2011-08-10 09:50:04 +02:00
|
|
|
LookupContext targetContext(targetFile->cppDocument(), snapshot);
|
|
|
|
|
|
|
|
|
|
Overview overview;
|
|
|
|
|
overview.setShowReturnTypes(true);
|
|
|
|
|
overview.setShowTemplateParameters(true);
|
|
|
|
|
overview.setShowArgumentNames(true);
|
|
|
|
|
overview.setShowFunctionSignatures(true);
|
|
|
|
|
|
|
|
|
|
// sync return type
|
|
|
|
|
{
|
|
|
|
|
// set up for rewriting return type
|
|
|
|
|
SubstitutionEnvironment env;
|
|
|
|
|
env.setContext(sourceContext);
|
|
|
|
|
env.switchScope(sourceFunction->enclosingScope());
|
|
|
|
|
ClassOrNamespace *targetCoN = targetContext.lookupType(targetFunction->enclosingScope());
|
|
|
|
|
if (!targetCoN)
|
|
|
|
|
targetCoN = targetContext.globalNamespace();
|
|
|
|
|
UseMinimalNames q(targetCoN);
|
|
|
|
|
env.enter(&q);
|
|
|
|
|
Control *control = sourceContext.control().data();
|
|
|
|
|
|
|
|
|
|
// get return type start position and declarator info from declaration
|
|
|
|
|
DeclaratorAST *declarator = 0;
|
2011-09-09 14:21:31 +02:00
|
|
|
SpecifierAST *firstReplaceableSpecifier = 0;
|
|
|
|
|
TranslationUnit *targetTranslationUnit = targetFile->cppDocument()->translationUnit();
|
2011-08-10 09:50:04 +02:00
|
|
|
if (SimpleDeclarationAST *simple = targetDeclaration->asSimpleDeclaration()) {
|
|
|
|
|
declarator = simple->declarator_list->value;
|
2011-09-09 14:21:31 +02:00
|
|
|
firstReplaceableSpecifier = findFirstReplaceableSpecifier(
|
|
|
|
|
targetTranslationUnit, simple->decl_specifier_list);
|
2011-08-10 09:50:04 +02:00
|
|
|
} else if (FunctionDefinitionAST *def = targetDeclaration->asFunctionDefinition()) {
|
|
|
|
|
declarator = def->declarator;
|
2011-09-09 14:21:31 +02:00
|
|
|
firstReplaceableSpecifier = findFirstReplaceableSpecifier(
|
|
|
|
|
targetTranslationUnit, def->decl_specifier_list);
|
2011-08-10 09:50:04 +02:00
|
|
|
}
|
|
|
|
|
|
2011-09-09 14:21:31 +02:00
|
|
|
int returnTypeStart = 0;
|
|
|
|
|
if (firstReplaceableSpecifier)
|
|
|
|
|
returnTypeStart = targetFile->startOf(firstReplaceableSpecifier);
|
|
|
|
|
else
|
|
|
|
|
returnTypeStart = targetFile->startOf(declarator);
|
|
|
|
|
|
2011-08-10 09:50:04 +02:00
|
|
|
if (!newFunction->returnType().isEqualTo(sourceFunction->returnType())
|
|
|
|
|
&& !newFunction->returnType().isEqualTo(targetFunction->returnType())) {
|
|
|
|
|
FullySpecifiedType type = rewriteType(newFunction->returnType(), &env, control);
|
|
|
|
|
const QString replacement = overview(type, targetFunction->name());
|
|
|
|
|
changes.replace(returnTypeStart,
|
2011-08-17 11:35:57 +02:00
|
|
|
targetFile->startOf(targetFunctionDeclarator->lparen_token),
|
2011-08-10 09:50:04 +02:00
|
|
|
replacement);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// sync parameters
|
|
|
|
|
{
|
|
|
|
|
// set up for rewriting parameter types
|
|
|
|
|
SubstitutionEnvironment env;
|
|
|
|
|
env.setContext(sourceContext);
|
|
|
|
|
env.switchScope(sourceFunction);
|
|
|
|
|
ClassOrNamespace *targetCoN = targetContext.lookupType(targetFunction);
|
|
|
|
|
if (!targetCoN)
|
|
|
|
|
targetCoN = targetContext.globalNamespace();
|
|
|
|
|
UseMinimalNames q(targetCoN);
|
|
|
|
|
env.enter(&q);
|
|
|
|
|
Control *control = sourceContext.control().data();
|
|
|
|
|
Overview overview;
|
|
|
|
|
|
2011-08-16 14:31:15 +02:00
|
|
|
const unsigned sourceArgCount = declaredArgumentCount(sourceFunction);
|
|
|
|
|
const unsigned newArgCount = declaredArgumentCount(newFunction);
|
|
|
|
|
const unsigned targetArgCount = declaredArgumentCount(targetFunction);
|
|
|
|
|
|
2011-08-10 09:50:04 +02:00
|
|
|
// check if parameter types or names have changed
|
2011-08-16 14:31:15 +02:00
|
|
|
const unsigned existingArgs = qMin(targetArgCount, newArgCount);
|
2011-08-10 09:50:04 +02:00
|
|
|
ParameterDeclarationClauseAST *targetParameterDecl =
|
|
|
|
|
targetFunctionDeclarator->parameter_declaration_clause;
|
|
|
|
|
ParameterDeclarationListAST *firstTargetParameterDeclIt =
|
|
|
|
|
targetParameterDecl ? targetParameterDecl->parameter_declaration_list : 0;
|
|
|
|
|
ParameterDeclarationListAST *targetParameterDeclIt = firstTargetParameterDeclIt;
|
|
|
|
|
for (unsigned i = 0;
|
|
|
|
|
i < existingArgs && targetParameterDeclIt;
|
|
|
|
|
++i, targetParameterDeclIt = targetParameterDeclIt->next) {
|
|
|
|
|
Symbol *targetParam = targetFunction->argumentAt(i);
|
|
|
|
|
Symbol *newParam = newFunction->argumentAt(i);
|
|
|
|
|
|
|
|
|
|
// if new's name and type are the same as source's, forbid changes
|
|
|
|
|
bool allowChangeType = true;
|
|
|
|
|
const Name *replacementName = newParam->name();
|
2011-08-16 14:31:15 +02:00
|
|
|
if (i < sourceArgCount) {
|
2011-08-10 09:50:04 +02:00
|
|
|
Symbol *sourceParam = sourceFunction->argumentAt(i);
|
|
|
|
|
if (newParam->type().isEqualTo(sourceParam->type()))
|
|
|
|
|
allowChangeType = false;
|
|
|
|
|
if (namesEqual(replacementName, sourceParam->name()))
|
|
|
|
|
replacementName = targetParam->name();
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-26 13:11:12 +02:00
|
|
|
// don't change the name if it's in a comment
|
|
|
|
|
if (hasCommentedName(targetFile->cppDocument()->translationUnit(),
|
|
|
|
|
targetFile->cppDocument()->source(),
|
|
|
|
|
targetFunctionDeclarator, i))
|
|
|
|
|
replacementName = 0;
|
|
|
|
|
|
|
|
|
|
// find the end of the parameter declaration
|
2011-08-10 09:50:04 +02:00
|
|
|
ParameterDeclarationAST *targetParamAst = targetParameterDeclIt->value;
|
|
|
|
|
int parameterNameEnd = 0;
|
|
|
|
|
if (targetParamAst->declarator)
|
2011-08-17 11:35:57 +02:00
|
|
|
parameterNameEnd = targetFile->endOf(targetParamAst->declarator);
|
2011-08-10 09:50:04 +02:00
|
|
|
else if (targetParamAst->type_specifier_list)
|
2011-08-17 11:35:57 +02:00
|
|
|
parameterNameEnd = targetFile->endOf(targetParamAst->type_specifier_list->lastToken() - 1);
|
2011-08-10 09:50:04 +02:00
|
|
|
else
|
2011-08-17 11:35:57 +02:00
|
|
|
parameterNameEnd = targetFile->startOf(targetParamAst);
|
2011-08-10 09:50:04 +02:00
|
|
|
|
2011-08-26 13:11:12 +02:00
|
|
|
// change name and type?
|
2011-08-10 09:50:04 +02:00
|
|
|
if (allowChangeType
|
|
|
|
|
&& !targetParam->type().isEqualTo(newParam->type())) {
|
|
|
|
|
FullySpecifiedType replacementType = rewriteType(newParam->type(), &env, control);
|
|
|
|
|
const QString replacement = overview(replacementType, replacementName);
|
|
|
|
|
|
2011-08-17 11:35:57 +02:00
|
|
|
changes.replace(targetFile->startOf(targetParamAst),
|
2011-08-10 09:50:04 +02:00
|
|
|
parameterNameEnd,
|
|
|
|
|
replacement);
|
2011-08-26 13:11:12 +02:00
|
|
|
}
|
|
|
|
|
// change the name only?
|
|
|
|
|
else if (!namesEqual(targetParam->name(), replacementName)) {
|
2011-08-10 09:50:04 +02:00
|
|
|
DeclaratorIdAST *id = getDeclaratorId(targetParamAst->declarator);
|
|
|
|
|
QString replacementNameStr = overview(replacementName);
|
|
|
|
|
if (id) {
|
2011-08-17 11:35:57 +02:00
|
|
|
changes.replace(targetFile->range(id), replacementNameStr);
|
2011-08-10 09:50:04 +02:00
|
|
|
} else {
|
|
|
|
|
// add name to unnamed parameter
|
|
|
|
|
replacementNameStr.prepend(QLatin1Char(' '));
|
|
|
|
|
int end;
|
|
|
|
|
if (targetParamAst->equal_token) {
|
2011-08-17 11:35:57 +02:00
|
|
|
end = targetFile->startOf(targetParamAst->equal_token);
|
2011-08-10 09:50:04 +02:00
|
|
|
replacementNameStr.append(QLatin1Char(' '));
|
|
|
|
|
} else {
|
|
|
|
|
// one past end on purpose
|
2011-08-17 11:35:57 +02:00
|
|
|
end = targetFile->startOf(targetParamAst->lastToken());
|
2011-08-10 09:50:04 +02:00
|
|
|
}
|
|
|
|
|
changes.replace(parameterNameEnd, end, replacementNameStr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-08-26 13:11:12 +02:00
|
|
|
// remove some parameters?
|
2011-08-16 14:31:15 +02:00
|
|
|
if (newArgCount < targetArgCount) {
|
2011-08-10 09:50:04 +02:00
|
|
|
targetParameterDeclIt = firstTargetParameterDeclIt;
|
|
|
|
|
if (targetParameterDeclIt) {
|
2011-08-16 14:31:15 +02:00
|
|
|
if (newArgCount == 0) {
|
2011-08-17 11:35:57 +02:00
|
|
|
changes.remove(targetFile->startOf(targetParameterDeclIt->firstToken()),
|
|
|
|
|
targetFile->endOf(targetParameterDeclIt->lastToken() - 1));
|
2011-08-10 09:50:04 +02:00
|
|
|
} else {
|
|
|
|
|
// get the last valid argument
|
2011-08-16 14:31:15 +02:00
|
|
|
for (unsigned i = 0; i < newArgCount - 1 && targetParameterDeclIt; ++i)
|
2011-08-10 09:50:04 +02:00
|
|
|
targetParameterDeclIt = targetParameterDeclIt->next;
|
|
|
|
|
if (targetParameterDeclIt) {
|
2011-08-17 11:35:57 +02:00
|
|
|
const int start = targetFile->endOf(targetParameterDeclIt->value);
|
|
|
|
|
const int end = targetFile->endOf(targetParameterDecl->lastToken() - 1);
|
2011-08-10 09:50:04 +02:00
|
|
|
changes.remove(start, end);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-08-26 13:11:12 +02:00
|
|
|
}
|
|
|
|
|
// add some parameters?
|
|
|
|
|
else if (newArgCount > targetArgCount) {
|
2011-08-10 09:50:04 +02:00
|
|
|
QString newParams;
|
2011-08-16 14:31:15 +02:00
|
|
|
for (unsigned i = targetArgCount; i < newArgCount; ++i) {
|
2011-08-10 09:50:04 +02:00
|
|
|
Symbol *param = newFunction->argumentAt(i);
|
|
|
|
|
FullySpecifiedType type = rewriteType(param->type(), &env, control);
|
|
|
|
|
if (i != 0)
|
|
|
|
|
newParams += QLatin1String(", ");
|
|
|
|
|
newParams += overview(type, param->name());
|
|
|
|
|
}
|
|
|
|
|
targetParameterDeclIt = firstTargetParameterDeclIt;
|
|
|
|
|
if (targetParameterDeclIt) {
|
|
|
|
|
while (targetParameterDeclIt->next)
|
|
|
|
|
targetParameterDeclIt = targetParameterDeclIt->next;
|
2011-08-17 11:35:57 +02:00
|
|
|
changes.insert(targetFile->endOf(targetParameterDeclIt->value), newParams);
|
2011-08-10 09:50:04 +02:00
|
|
|
} else {
|
2011-08-17 11:35:57 +02:00
|
|
|
changes.insert(targetFile->endOf(targetFunctionDeclarator->lparen_token), newParams);
|
2011-08-10 09:50:04 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// sync cv qualification
|
|
|
|
|
if (targetFunction->isConst() != newFunction->isConst()
|
|
|
|
|
|| targetFunction->isVolatile() != newFunction->isVolatile()) {
|
|
|
|
|
QString cvString;
|
|
|
|
|
if (newFunction->isConst())
|
|
|
|
|
cvString += QLatin1String("const");
|
|
|
|
|
if (newFunction->isVolatile()) {
|
|
|
|
|
if (!cvString.isEmpty())
|
|
|
|
|
cvString += QLatin1Char(' ');
|
|
|
|
|
cvString += QLatin1String("volatile");
|
|
|
|
|
}
|
2011-08-17 11:35:57 +02:00
|
|
|
const int rparenEnd = targetFile->endOf(targetFunctionDeclarator->rparen_token);
|
2011-08-10 09:50:04 +02:00
|
|
|
if (targetFunctionDeclarator->cv_qualifier_list) {
|
2011-08-17 11:35:57 +02:00
|
|
|
const int cvEnd = targetFile->endOf(targetFunctionDeclarator->cv_qualifier_list->lastToken() - 1);
|
2011-08-10 09:50:04 +02:00
|
|
|
// if the qualifies changed, replace
|
|
|
|
|
if (!cvString.isEmpty()) {
|
2011-08-17 11:35:57 +02:00
|
|
|
changes.replace(targetFile->startOf(targetFunctionDeclarator->cv_qualifier_list->firstToken()),
|
2011-08-10 09:50:04 +02:00
|
|
|
cvEnd, cvString);
|
|
|
|
|
} else {
|
|
|
|
|
// remove
|
|
|
|
|
changes.remove(rparenEnd, cvEnd);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// otherwise add
|
|
|
|
|
cvString.prepend(QLatin1Char(' '));
|
|
|
|
|
changes.insert(rparenEnd, cvString);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-17 14:11:35 +02:00
|
|
|
if (targetOffset != -1) {
|
|
|
|
|
// move all change operations to have the right start offset
|
|
|
|
|
const int moveAmount = targetOffset - targetFile->startOf(targetDeclaration);
|
|
|
|
|
QList<Utils::ChangeSet::EditOp> ops = changes.operationList();
|
|
|
|
|
for (int i = 0; i < ops.size(); ++i) {
|
|
|
|
|
ops[i].pos1 += moveAmount;
|
|
|
|
|
ops[i].pos2 += moveAmount;
|
|
|
|
|
}
|
|
|
|
|
changes = Utils::ChangeSet(ops);
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-10 09:50:04 +02:00
|
|
|
return changes;
|
|
|
|
|
}
|
2011-09-05 10:33:17 +02:00
|
|
|
|
|
|
|
|
class ApplyDeclDefLinkOperation : public CppQuickFixOperation
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit ApplyDeclDefLinkOperation(
|
|
|
|
|
const QSharedPointer<const Internal::CppQuickFixAssistInterface> &interface,
|
|
|
|
|
const QSharedPointer<FunctionDeclDefLink> &link,
|
|
|
|
|
int priority = -1)
|
|
|
|
|
: CppQuickFixOperation(interface, priority)
|
|
|
|
|
, m_link(link)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
virtual void perform()
|
|
|
|
|
{
|
|
|
|
|
CPPEditorWidget *editor = assistInterface()->editor();
|
|
|
|
|
QSharedPointer<FunctionDeclDefLink> link = editor->declDefLink();
|
|
|
|
|
if (link != m_link)
|
|
|
|
|
return;
|
|
|
|
|
|
2011-09-12 15:02:30 +02:00
|
|
|
return editor->applyDeclDefLinkChanges(/*don't jump*/false);
|
2011-09-05 10:33:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual void performChanges(const CppTools::CppRefactoringFilePtr &, const CppTools::CppRefactoringChanges &)
|
|
|
|
|
{ /* never called since perform is overridden */ }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QSharedPointer<FunctionDeclDefLink> m_link;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QList<CppQuickFixOperation::Ptr> ApplyDeclDefLinkChanges::match(const QSharedPointer<const CppQuickFixAssistInterface> &interface)
|
|
|
|
|
{
|
|
|
|
|
QList<CppQuickFixOperation::Ptr> results;
|
|
|
|
|
|
|
|
|
|
QSharedPointer<FunctionDeclDefLink> link = interface->editor()->declDefLink();
|
|
|
|
|
if (!link || !link->isMarkerVisible())
|
|
|
|
|
return results;
|
|
|
|
|
|
|
|
|
|
QSharedPointer<ApplyDeclDefLinkOperation> op(new ApplyDeclDefLinkOperation(interface, link));
|
|
|
|
|
op->setDescription(FunctionDeclDefLink::tr("Apply function signature changes"));
|
|
|
|
|
op->setPriority(0);
|
|
|
|
|
results += op;
|
|
|
|
|
|
|
|
|
|
return results;
|
|
|
|
|
}
|