Skip to content
Snippets Groups Projects
Commit 67e2ecb6 authored by Christian Kamm's avatar Christian Kamm
Browse files

QuickFix: rename contains->isCursorOn, remove selectNode,selectToken


Reviewed-by: default avatarRoberto Raggi <roberto.raggi@nokia.com>
parent ebfe9905
No related branches found
No related tags found
No related merge requests found
...@@ -124,7 +124,7 @@ public: ...@@ -124,7 +124,7 @@ public:
if (! expression) if (! expression)
return -1; return -1;
if (! contains(expression->binary_op_token)) if (! isCursorOn(expression->binary_op_token))
return -1; return -1;
left = mk.UnaryExpression(); left = mk.UnaryExpression();
...@@ -223,7 +223,7 @@ public: ...@@ -223,7 +223,7 @@ public:
if (cursorPosition >= startOfDeclSpecifier && cursorPosition <= endOfDeclSpecifier) if (cursorPosition >= startOfDeclSpecifier && cursorPosition <= endOfDeclSpecifier)
return index; // the AST node under cursor is a specifier. 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. return index; // got a core-declarator under the text cursor.
} }
...@@ -286,7 +286,7 @@ public: ...@@ -286,7 +286,7 @@ public:
// show when we're on the 'if' of an if statement // show when we're on the 'if' of an if statement
int index = path.size() - 1; int index = path.size() - 1;
IfStatementAST *ifStatement = path.at(index)->asIfStatement(); IfStatementAST *ifStatement = path.at(index)->asIfStatement();
if (ifStatement && contains(ifStatement->if_token) if (ifStatement && isCursorOn(ifStatement->if_token)
&& ! ifStatement->statement->asCompoundStatement()) { && ! ifStatement->statement->asCompoundStatement()) {
_statement = ifStatement->statement; _statement = ifStatement->statement;
return index; return index;
...@@ -296,7 +296,7 @@ public: ...@@ -296,7 +296,7 @@ public:
// ### This may not be such a good idea, consider nested ifs... // ### This may not be such a good idea, consider nested ifs...
for (; index != -1; --index) { for (; index != -1; --index) {
IfStatementAST *ifStatement = path.at(index)->asIfStatement(); IfStatementAST *ifStatement = path.at(index)->asIfStatement();
if (ifStatement && contains(ifStatement->statement) if (ifStatement && isCursorOn(ifStatement->statement)
&& ! ifStatement->statement->asCompoundStatement()) { && ! ifStatement->statement->asCompoundStatement()) {
_statement = ifStatement->statement; _statement = ifStatement->statement;
return index; return index;
...@@ -357,7 +357,7 @@ public: ...@@ -357,7 +357,7 @@ public:
if (! core) if (! core)
return -1; return -1;
if (contains(core)) if (isCursorOn(core))
return index; return index;
} }
} }
...@@ -368,8 +368,8 @@ public: ...@@ -368,8 +368,8 @@ public:
virtual void apply() virtual void apply()
{ {
const QString name = selectNode(core).selectedText(); const QString name = textOf(core);
QString declaration = selectNode(condition).selectedText(); QString declaration = textOf(condition);
declaration += QLatin1String(";\n"); declaration += QLatin1String(";\n");
insert(startOf(pattern), declaration); insert(startOf(pattern), declaration);
...@@ -432,7 +432,7 @@ public: ...@@ -432,7 +432,7 @@ public:
else if (! declarator->initializer) else if (! declarator->initializer)
return -1; return -1;
if (contains(core)) if (isCursorOn(core))
return index; return index;
} }
} }
...@@ -531,7 +531,7 @@ public: ...@@ -531,7 +531,7 @@ public:
Token binaryToken = tokenAt(condition->binary_op_token); Token binaryToken = tokenAt(condition->binary_op_token);
if (binaryToken.is(T_AMPER_AMPER) || binaryToken.is(T_PIPE_PIPE)) { 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; return index;
} else { } else {
return -1; return -1;
...@@ -661,7 +661,7 @@ int QuickFixOperation::endOf(const CPlusPlus::AST *ast) const ...@@ -661,7 +661,7 @@ int QuickFixOperation::endOf(const CPlusPlus::AST *ast) const
return endOf(ast->lastToken() - 1); return endOf(ast->lastToken() - 1);
} }
bool QuickFixOperation::contains(unsigned tokenIndex) const bool QuickFixOperation::isCursorOn(unsigned tokenIndex) const
{ {
QTextCursor tc = textCursor(); QTextCursor tc = textCursor();
int cursorBegin = tc.selectionStart(); int cursorBegin = tc.selectionStart();
...@@ -675,7 +675,7 @@ bool QuickFixOperation::contains(unsigned tokenIndex) const ...@@ -675,7 +675,7 @@ bool QuickFixOperation::contains(unsigned tokenIndex) const
return false; return false;
} }
bool QuickFixOperation::contains(const CPlusPlus::AST *ast) const bool QuickFixOperation::isCursorOn(const CPlusPlus::AST *ast) const
{ {
QTextCursor tc = textCursor(); QTextCursor tc = textCursor();
int cursorBegin = tc.selectionStart(); int cursorBegin = tc.selectionStart();
...@@ -689,22 +689,6 @@ bool QuickFixOperation::contains(const CPlusPlus::AST *ast) const ...@@ -689,22 +689,6 @@ bool QuickFixOperation::contains(const CPlusPlus::AST *ast) const
return false; 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 QuickFixOperation::Range QuickFixOperation::createRange(AST *ast) const
{ {
QTextCursor tc = _textCursor; QTextCursor tc = _textCursor;
...@@ -768,7 +752,7 @@ QString QuickFixOperation::textOf(int firstOffset, int lastOffset) const ...@@ -768,7 +752,7 @@ QString QuickFixOperation::textOf(int firstOffset, int lastOffset) const
QString QuickFixOperation::textOf(AST *ast) const QString QuickFixOperation::textOf(AST *ast) const
{ {
return selectNode(ast).selectedText(); return textOf(startOf(ast), endOf(ast));
} }
void QuickFixOperation::applyChanges(AST *ast) void QuickFixOperation::applyChanges(AST *ast)
......
...@@ -77,16 +77,14 @@ public: ...@@ -77,16 +77,14 @@ public:
protected: protected:
const CPlusPlus::Token &tokenAt(unsigned index) const; 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(unsigned index) const;
int startOf(const CPlusPlus::AST *ast) const; int startOf(const CPlusPlus::AST *ast) const;
int endOf(unsigned index) const; int endOf(unsigned index) const;
int endOf(const CPlusPlus::AST *ast) const; int endOf(const CPlusPlus::AST *ast) const;
bool contains(unsigned tokenIndex) const; bool isCursorOn(unsigned tokenIndex) const;
bool contains(const CPlusPlus::AST *ast) const; bool isCursorOn(const CPlusPlus::AST *ast) const;
void move(int start, int end, int to); void move(int start, int end, int to);
void move(unsigned tokenIndex, int to); void move(unsigned tokenIndex, int to);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment