diff options
author | Christian Kamm <christian.d.kamm@nokia.com> | 2010-08-13 12:49:11 +0200 |
---|---|---|
committer | Christian Kamm <christian.d.kamm@nokia.com> | 2010-08-13 12:51:22 +0200 |
commit | 7a5df3c39dc6bd16ceec4e15da62b96dd70090aa (patch) | |
tree | 776f98eca91e5ac236055e2353043d373c5ead0d /src/plugins/cppeditor/cppquickfix.cpp | |
parent | bbe64796a0f3a8c57718a5121fff85ba0b14c7a0 (diff) |
QuickFix: Move helpers from QuickFixData to RefactoringFile.
Makes them easy to use everywhere. Also when calling
QuickFixData::textOf and friends, it wasn't really clear which file
they would run on.
Diffstat (limited to 'src/plugins/cppeditor/cppquickfix.cpp')
-rw-r--r-- | src/plugins/cppeditor/cppquickfix.cpp | 93 |
1 files changed, 2 insertions, 91 deletions
diff --git a/src/plugins/cppeditor/cppquickfix.cpp b/src/plugins/cppeditor/cppquickfix.cpp index c85e776f3a..49d56dc936 100644 --- a/src/plugins/cppeditor/cppquickfix.cpp +++ b/src/plugins/cppeditor/cppquickfix.cpp @@ -86,100 +86,11 @@ const LookupContext &CppQuickFixState::context() const return _context; } -Scope *CppQuickFixState::scopeAt(unsigned index) const +const CppRefactoringFile CppQuickFixState::currentFile() const { - unsigned line, column; - document()->translationUnit()->getTokenStartPosition(index, &line, &column); - return document()->scopeAt(line, column); + return CppRefactoringFile(editor(), document()); } -bool CppQuickFixState::isCursorOn(unsigned tokenIndex) const -{ - QTextCursor tc = textCursor(); - int cursorBegin = tc.selectionStart(); - - int start = startOf(tokenIndex); - int end = endOf(tokenIndex); - - if (cursorBegin >= start && cursorBegin <= end) - return true; - - return false; -} - -bool CppQuickFixState::isCursorOn(const AST *ast) const -{ - QTextCursor tc = textCursor(); - int cursorBegin = tc.selectionStart(); - - int start = startOf(ast); - int end = endOf(ast); - - if (cursorBegin >= start && cursorBegin <= end) - return true; - - return false; -} - -ChangeSet::Range CppQuickFixState::range(unsigned tokenIndex) const -{ - const Token &token = tokenAt(tokenIndex); - unsigned line, column; - document()->translationUnit()->getPosition(token.begin(), &line, &column); - const int start = editor()->document()->findBlockByNumber(line - 1).position() + column - 1; - return ChangeSet::Range(start, start + token.length()); -} - -ChangeSet::Range CppQuickFixState::range(AST *ast) const -{ - return ChangeSet::Range(startOf(ast), endOf(ast)); -} - -int CppQuickFixState::startOf(unsigned index) const -{ - unsigned line, column; - document()->translationUnit()->getPosition(tokenAt(index).begin(), &line, &column); - return editor()->document()->findBlockByNumber(line - 1).position() + column - 1; -} - -int CppQuickFixState::startOf(const AST *ast) const -{ - return startOf(ast->firstToken()); -} - -int CppQuickFixState::endOf(unsigned index) const -{ - unsigned line, column; - document()->translationUnit()->getPosition(tokenAt(index).end(), &line, &column); - return editor()->document()->findBlockByNumber(line - 1).position() + column - 1; -} - -int CppQuickFixState::endOf(const AST *ast) const -{ - if (unsigned end = ast->lastToken()) - return endOf(end - 1); - else - return 0; -} - -void CppQuickFixState::startAndEndOf(unsigned index, int *start, int *end) const -{ - unsigned line, column; - Token token(tokenAt(index)); - document()->translationUnit()->getPosition(token.begin(), &line, &column); - *start = editor()->document()->findBlockByNumber(line - 1).position() + column - 1; - *end = *start + token.length(); -} - -QString CppQuickFixState::textOf(const AST *ast) const -{ - return textOf(startOf(ast), endOf(ast)); -} - -const Token &CppQuickFixState::tokenAt(unsigned index) const -{ - return document()->translationUnit()->tokenAt(index); -} CppQuickFixOperation::CppQuickFixOperation(const CppQuickFixState &state, int priority) : QuickFixOperation(priority) |