From 76ebb4647930bf17b394c5610e26930a0af491d9 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Mon, 5 Jul 2010 13:34:27 +0200 Subject: [PATCH] Fixed: "Follow symbol" on constructor or destructor always jumps to class definition Task-number: QTCREATORBUG-1776 --- src/libs/cplusplus/CppDocument.cpp | 16 ++++------------ src/plugins/cppeditor/cppeditor.cpp | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/libs/cplusplus/CppDocument.cpp b/src/libs/cplusplus/CppDocument.cpp index e8dd8647465..bbf3eac045e 100644 --- a/src/libs/cplusplus/CppDocument.cpp +++ b/src/libs/cplusplus/CppDocument.cpp @@ -703,25 +703,17 @@ public: }; } // end of anonymous namespace -Symbol *Snapshot::findMatchingDefinition(Symbol *symbol) const +Symbol *Snapshot::findMatchingDefinition(Symbol *declaration) const { - if (! symbol->identifier()) + if (! (declaration && declaration->identifier())) return 0; - Document::Ptr thisDocument = document(QString::fromUtf8(symbol->fileName(), symbol->fileNameLength())); + Document::Ptr thisDocument = document(QString::fromUtf8(declaration->fileName(), declaration->fileNameLength())); if (! thisDocument) { - qWarning() << "undefined document:" << symbol->fileName(); + qWarning() << "undefined document:" << declaration->fileName(); return 0; } - LookupContext thisContext(thisDocument, *this); - const QList declarationCandidates = thisContext.lookup(symbol->name(), symbol->scope()); - if (declarationCandidates.isEmpty()) { - qWarning() << "unresolved declaration:" << symbol->fileName() << symbol->line() << symbol->column(); - return 0; - } - - Symbol *declaration = declarationCandidates.first(); Function *declarationTy = declaration->type()->asFunctionType(); if (! declarationTy) { qWarning() << "not a function:" << declaration->fileName() << declaration->line() << declaration->column(); diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index ec7cd022e87..c52f7a66283 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -1238,7 +1238,20 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor, const QList resolvedSymbols = typeOfExpression(expression, scope, TypeOfExpression::Preprocess); if (!resolvedSymbols.isEmpty()) { - const LookupItem result = skipForwardDeclarations(resolvedSymbols); + LookupItem result = skipForwardDeclarations(resolvedSymbols); + + foreach (const LookupItem &r, resolvedSymbols) { + if (Symbol *d = r.declaration()) { + if (d->isDeclaration() || d->isFunction()) { + if (file()->fileName() == QString::fromUtf8(d->fileName(), d->fileNameLength())) { + if (unsigned(line) == d->line() && unsigned(column) >= d->column()) { // ### TODO: check the end + result = r; // take the symbol under cursor. + break; + } + } + } + } + } if (Symbol *symbol = result.declaration()) { Symbol *def = 0;