Fixed `look at symbol under cursor' when symbol is a Qt method (e.g. a signal).

Done with: erikv
This commit is contained in:
Roberto Raggi
2010-03-29 15:30:53 +02:00
parent a67e88993b
commit 678f7d3e94
8 changed files with 105 additions and 38 deletions

View File

@@ -119,7 +119,7 @@ QStringRef BackwardsScanner::textRef(int index) const
return _text.midRef(firstToken.begin(), firstToken.length());
}
int BackwardsScanner::previousBlockState(const QTextBlock &block) const
int BackwardsScanner::previousBlockState(const QTextBlock &block)
{
const QTextBlock prevBlock = block.previous();

View File

@@ -67,7 +67,7 @@ public:
int startOfMatchingBrace(int index) const;
int startOfBlock(int index) const;
int previousBlockState(const QTextBlock &block) const;
static int previousBlockState(const QTextBlock &block);
int size() const;

View File

@@ -56,7 +56,6 @@ public:
private:
int startOfExpression(BackwardsScanner &tk, int index);
int startOfExpression_helper(BackwardsScanner &tk, int index);
int previousBlockState(const QTextBlock &block);
bool isAccessToken(const SimpleToken &tk);
private:

View File

@@ -120,6 +120,25 @@ QList<Scope *> ResolveExpression::visibleScopes(const LookupItem &result) const
bool ResolveExpression::visit(BinaryExpressionAST *ast)
{
if (tokenKind(ast->binary_op_token) == T_COMMA && ast->right_expression && ast->right_expression->asQtMethod() != 0) {
if (ast->left_expression && ast->left_expression->asQtMethod() != 0)
thisObject();
else
accept(ast->left_expression);
QtMethodAST *qtMethod = ast->right_expression->asQtMethod();
if (DeclaratorAST *d = qtMethod->declarator) {
if (d->core_declarator) {
if (DeclaratorIdAST *declaratorId = d->core_declarator->asDeclaratorId())
if (NameAST *nameAST = declaratorId->name)
_results = resolveMemberExpression(_results, T_ARROW, nameAST->name);
}
}
return false;
}
accept(ast->left_expression);
return false;
}
@@ -263,9 +282,15 @@ bool ResolveExpression::visit(BoolLiteralAST *)
}
bool ResolveExpression::visit(ThisExpressionAST *)
{
thisObject();
return false;
}
void ResolveExpression::thisObject()
{
if (! _context.symbol())
return false;
return;
Scope *scope = _context.symbol()->scope();
for (; scope; scope = scope->enclosingScope()) {
@@ -290,7 +315,6 @@ bool ResolveExpression::visit(ThisExpressionAST *)
}
}
}
return false;
}
bool ResolveExpression::visit(CompoundExpressionAST *ast)

View File

@@ -63,6 +63,7 @@ public:
protected:
QList<LookupItem> switchResults(const QList<LookupItem> &symbols);
void thisObject();
void addResult(const FullySpecifiedType &ty, Symbol *symbol = 0);
void addResult(const LookupItem &result);
void addResults(const QList<LookupItem> &results);

View File

@@ -28,6 +28,7 @@
**************************************************************************/
#include "TokenUnderCursor.h"
#include "BackwardsScanner.h"
#include <Token.h>
#include <QTextCursor>
@@ -52,7 +53,7 @@ SimpleToken TokenUnderCursor::operator()(const QTextCursor &cursor, QTextBlock *
int column = cursor.position() - cursor.block().position();
_text = block.text();
_tokens = tokenize(_text, previousBlockState(block));
_tokens = tokenize(_text, BackwardsScanner::previousBlockState(block));
for (int index = _tokens.size() - 1; index != -1; --index) {
const SimpleToken &tk = _tokens.at(index);
if (tk.position() < column) {
@@ -64,15 +65,3 @@ SimpleToken TokenUnderCursor::operator()(const QTextCursor &cursor, QTextBlock *
return SimpleToken();
}
int TokenUnderCursor::previousBlockState(const QTextBlock &block) const
{
const QTextBlock prevBlock = block.previous();
if (prevBlock.isValid()) {
int state = prevBlock.userState();
if (state != -1)
return state;
}
return 0;
}

View File

@@ -52,8 +52,6 @@ public:
{ return _tokens; }
private:
int previousBlockState(const QTextBlock &block) const;
QList<SimpleToken> _tokens;
QString _text;
};