diff --git a/src/plugins/cppeditor/cppquickfix.cpp b/src/plugins/cppeditor/cppquickfix.cpp index 691982e6e4ff4ef638c167606f18672161545392..f5b43c0a9babe7d29fdfd4c9d92d3264627113a2 100644 --- a/src/plugins/cppeditor/cppquickfix.cpp +++ b/src/plugins/cppeditor/cppquickfix.cpp @@ -124,7 +124,7 @@ public: if (! expression) return -1; - if (! contains(expression->binary_op_token)) + if (! isCursorOn(expression->binary_op_token)) return -1; left = mk.UnaryExpression(); @@ -223,7 +223,7 @@ public: if (cursorPosition >= startOfDeclSpecifier && cursorPosition <= endOfDeclSpecifier) return index; // the AST node under cursor is a specifier. - if (core_declarator && contains(core_declarator)) + if (core_declarator && isCursorOn(core_declarator)) return index; // got a core-declarator under the text cursor. } @@ -286,7 +286,7 @@ public: // show when we're on the 'if' of an if statement int index = path.size() - 1; IfStatementAST *ifStatement = path.at(index)->asIfStatement(); - if (ifStatement && contains(ifStatement->if_token) + if (ifStatement && isCursorOn(ifStatement->if_token) && ! ifStatement->statement->asCompoundStatement()) { _statement = ifStatement->statement; return index; @@ -296,7 +296,7 @@ public: // ### This may not be such a good idea, consider nested ifs... for (; index != -1; --index) { IfStatementAST *ifStatement = path.at(index)->asIfStatement(); - if (ifStatement && contains(ifStatement->statement) + if (ifStatement && isCursorOn(ifStatement->statement) && ! ifStatement->statement->asCompoundStatement()) { _statement = ifStatement->statement; return index; @@ -357,7 +357,7 @@ public: if (! core) return -1; - if (contains(core)) + if (isCursorOn(core)) return index; } } @@ -368,8 +368,8 @@ public: virtual void apply() { - const QString name = selectNode(core).selectedText(); - QString declaration = selectNode(condition).selectedText(); + const QString name = textOf(core); + QString declaration = textOf(condition); declaration += QLatin1String(";\n"); insert(startOf(pattern), declaration); @@ -432,7 +432,7 @@ public: else if (! declarator->initializer) return -1; - if (contains(core)) + if (isCursorOn(core)) return index; } } @@ -531,7 +531,7 @@ public: Token binaryToken = tokenAt(condition->binary_op_token); if (binaryToken.is(T_AMPER_AMPER) || binaryToken.is(T_PIPE_PIPE)) { - if (contains(condition->binary_op_token)) + if (isCursorOn(condition->binary_op_token)) return index; } else { return -1; @@ -661,7 +661,7 @@ int QuickFixOperation::endOf(const CPlusPlus::AST *ast) const return endOf(ast->lastToken() - 1); } -bool QuickFixOperation::contains(unsigned tokenIndex) const +bool QuickFixOperation::isCursorOn(unsigned tokenIndex) const { QTextCursor tc = textCursor(); int cursorBegin = tc.selectionStart(); @@ -675,7 +675,7 @@ bool QuickFixOperation::contains(unsigned tokenIndex) const return false; } -bool QuickFixOperation::contains(const CPlusPlus::AST *ast) const +bool QuickFixOperation::isCursorOn(const CPlusPlus::AST *ast) const { QTextCursor tc = textCursor(); int cursorBegin = tc.selectionStart(); @@ -689,22 +689,6 @@ bool QuickFixOperation::contains(const CPlusPlus::AST *ast) const return false; } -QTextCursor QuickFixOperation::selectToken(unsigned index) const -{ - QTextCursor tc = _textCursor; - tc.setPosition(startOf(index)); - tc.setPosition(endOf(index), QTextCursor::KeepAnchor); - return tc; -} - -QTextCursor QuickFixOperation::selectNode(AST *ast) const -{ - QTextCursor tc = _textCursor; - tc.setPosition(startOf(ast->firstToken())); - tc.setPosition(endOf(ast->lastToken() - 1), QTextCursor::KeepAnchor); - return tc; -} - QuickFixOperation::Range QuickFixOperation::createRange(AST *ast) const { QTextCursor tc = _textCursor; @@ -768,7 +752,7 @@ QString QuickFixOperation::textOf(int firstOffset, int lastOffset) const QString QuickFixOperation::textOf(AST *ast) const { - return selectNode(ast).selectedText(); + return textOf(startOf(ast), endOf(ast)); } void QuickFixOperation::applyChanges(AST *ast) diff --git a/src/plugins/cppeditor/cppquickfix.h b/src/plugins/cppeditor/cppquickfix.h index 17bcc997558ca711cd270302f39ac257512e1d3f..a9f1b8c90001d433cfcd6035c914df68ce9a89c9 100644 --- a/src/plugins/cppeditor/cppquickfix.h +++ b/src/plugins/cppeditor/cppquickfix.h @@ -77,16 +77,14 @@ public: protected: const CPlusPlus::Token &tokenAt(unsigned index) const; - QTextCursor selectToken(unsigned index) const; - QTextCursor selectNode(CPlusPlus::AST *ast) const; int startOf(unsigned index) const; int startOf(const CPlusPlus::AST *ast) const; int endOf(unsigned index) const; int endOf(const CPlusPlus::AST *ast) const; - bool contains(unsigned tokenIndex) const; - bool contains(const CPlusPlus::AST *ast) const; + bool isCursorOn(unsigned tokenIndex) const; + bool isCursorOn(const CPlusPlus::AST *ast) const; void move(int start, int end, int to); void move(unsigned tokenIndex, int to);