From ffc00e5ea0b1e6b39e9852fcff11e696d356c7b2 Mon Sep 17 00:00:00 2001 From: hjk Date: Mon, 8 Sep 2014 13:55:47 +0200 Subject: [PATCH] CppEditor: Denoise cppfunctiondecldeflink.cpp Namespaces, one overly flexible function template. Change-Id: I229127f28dbc6460999d80e7c28152205dfca356 Reviewed-by: Nikolai Kosjar --- .../cppeditor/cppfunctiondecldeflink.cpp | 54 ++++++++++--------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/src/plugins/cppeditor/cppfunctiondecldeflink.cpp b/src/plugins/cppeditor/cppfunctiondecldeflink.cpp index 9647ed58787..81938ebbc6e 100644 --- a/src/plugins/cppeditor/cppfunctiondecldeflink.cpp +++ b/src/plugins/cppeditor/cppfunctiondecldeflink.cpp @@ -52,12 +52,13 @@ #include using namespace CPlusPlus; -using namespace CppEditor; -using namespace CppEditor::Internal; using namespace CppTools; using namespace TextEditor; using namespace Utils; +namespace CppEditor { +namespace Internal { + FunctionDeclDefLinkFinder::FunctionDeclDefLinkFinder(QObject *parent) : QObject(parent) { @@ -124,7 +125,7 @@ static bool findDeclOrDef(const Document::Ptr &doc, int line, int column, return *funcDecl; } -static void declDefLinkStartEnd(const CppTools::CppRefactoringFileConstPtr &file, +static void declDefLinkStartEnd(const CppRefactoringFileConstPtr &file, DeclarationAST *parent, FunctionDeclaratorAST *funcDecl, int *start, int *end) { @@ -150,14 +151,14 @@ static DeclaratorIdAST *getDeclaratorId(DeclaratorAST *declarator) return 0; } -static QSharedPointer findLinkHelper(QSharedPointer link, CppTools::CppRefactoringChanges changes) +static QSharedPointer findLinkHelper(QSharedPointer link, CppRefactoringChanges changes) { QSharedPointer noResult; const Snapshot &snapshot = changes.snapshot(); // find the matching decl/def symbol Symbol *target = 0; - CppTools::SymbolFinder finder; + SymbolFinder finder; if (FunctionDefinitionAST *funcDef = link->sourceDeclaration->asFunctionDefinition()) { QList nameMatch, argumentCountMatch, typeMatch; finder.findMatchingDeclaration(LookupContext(link->sourceDocument, snapshot), @@ -174,7 +175,7 @@ static QSharedPointer findLinkHelper(QSharedPointerfileName(), target->fileNameLength()); - CppTools::CppRefactoringFileConstPtr targetFile = changes.fileNoEditor(targetFileName); + CppRefactoringFileConstPtr targetFile = changes.fileNoEditor(targetFileName); if (!targetFile->isValid()) return noResult; @@ -221,8 +222,8 @@ void FunctionDeclDefLinkFinder::startFindLinkAt( return; // find the start/end offsets - CppTools::CppRefactoringChanges refactoringChanges(snapshot); - CppTools::CppRefactoringFilePtr sourceFile = refactoringChanges.file(doc->fileName()); + CppRefactoringChanges refactoringChanges(snapshot); + CppRefactoringFilePtr sourceFile = refactoringChanges.file(doc->fileName()); sourceFile->setCppDocument(doc); int start, end; declDefLinkStartEnd(sourceFile, parent, funcDecl, &start, &end); @@ -292,14 +293,14 @@ 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); - CppTools::CppRefactoringFilePtr newTargetFile = refactoringChanges.file(targetFile->fileName()); + CppRefactoringChanges refactoringChanges(snapshot); + CppRefactoringFilePtr newTargetFile = refactoringChanges.file(targetFile->fileName()); if (!newTargetFile->isValid()) return; 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); + const ChangeSet changeset = changes(snapshot, targetStart); newTargetFile->setChangeSet(changeset); if (jumpToMatch) { const int jumpTarget = newTargetFile->position(targetFunction->line(), targetFunction->column()); @@ -312,12 +313,11 @@ void FunctionDeclDefLink::apply(CppEditorWidget *editor, bool jumpToMatch) } } -template -static QList removeMarkersOfType(const QList &markers) +static QList removeDeclDefLinkMarkers(const QList &markers) { - QList result; - foreach (const TextEditor::RefactorMarker &marker, markers) { - if (!marker.data.canConvert()) + QList result; + foreach (const RefactorMarker &marker, markers) { + if (!marker.data.canConvert()) result += marker; } return result; @@ -327,8 +327,7 @@ void FunctionDeclDefLink::hideMarker(CppEditorWidget *editor) { if (!hasMarker) return; - editor->setRefactorMarkers( - removeMarkersOfType(editor->refactorMarkers())); + editor->setRefactorMarkers(removeDeclDefLinkMarkers(editor->refactorMarkers())); hasMarker = false; } @@ -337,8 +336,8 @@ void FunctionDeclDefLink::showMarker(CppEditorWidget *editor) if (hasMarker) return; - QList markers = removeMarkersOfType(editor->refactorMarkers()); - TextEditor::RefactorMarker marker; + QList markers = removeDeclDefLinkMarkers(editor->refactorMarkers()); + RefactorMarker marker; // show the marker at the end of the linked area, with a special case // to avoid it overlapping with a trailing semicolon @@ -359,7 +358,7 @@ void FunctionDeclDefLink::showMarker(CppEditorWidget *editor) Core::Command *quickfixCommand = Core::ActionManager::command(TextEditor::Constants::QUICKFIX_THIS); if (quickfixCommand) - message = Utils::ProxyAction::stringWithAppendedShortcut(message, quickfixCommand->keySequence()); + message = ProxyAction::stringWithAppendedShortcut(message, quickfixCommand->keySequence()); marker.tooltip = message; marker.data = QVariant::fromValue(Marker()); @@ -531,7 +530,7 @@ static QString ensureCorrectParameterSpacing(const QString &text, bool isFirstPa return text; } -static unsigned findCommaTokenBetween(const CppTools::CppRefactoringFileConstPtr &file, +static unsigned findCommaTokenBetween(const CppRefactoringFileConstPtr &file, ParameterDeclarationAST *left, ParameterDeclarationAST *right) { unsigned last = left->lastToken() - 1; @@ -544,9 +543,9 @@ static unsigned findCommaTokenBetween(const CppTools::CppRefactoringFileConstPtr return 0; } -Utils::ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot, int targetOffset) +ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot, int targetOffset) { - Utils::ChangeSet changes; + ChangeSet changes; // Everything prefixed with 'new' in this function relates to the state of the 'source' // function *after* the user did his changes. @@ -962,13 +961,16 @@ Utils::ChangeSet FunctionDeclDefLink::changes(const Snapshot &snapshot, int targ if (targetOffset != -1) { // move all change operations to have the right start offset const int moveAmount = targetOffset - targetFile->startOf(targetDeclaration); - QList ops = changes.operationList(); + QList ops = changes.operationList(); for (int i = 0; i < ops.size(); ++i) { ops[i].pos1 += moveAmount; ops[i].pos2 += moveAmount; } - changes = Utils::ChangeSet(ops); + changes = ChangeSet(ops); } return changes; } + +} // namespace Internal +} // namespace CppEditor