From 3a4765e27653be17e454a3dd062cb3a8b06851ce Mon Sep 17 00:00:00 2001 From: Roberto Raggi <roberto.raggi@nokia.com> Date: Fri, 10 Dec 2010 10:47:57 +0100 Subject: [PATCH] Try to get the right overload when switching from a declaration to its definition. --- src/plugins/cppeditor/cppeditor.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index f80b61291f4..a0cbdef53fc 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -1108,21 +1108,30 @@ void CPPEditor::switchDeclarationDefinition() if (! lastVisibleSymbol) return; - Function *functionScope = lastVisibleSymbol->asFunction(); - if (! functionScope) - functionScope = lastVisibleSymbol->enclosingFunction(); + Function *function = lastVisibleSymbol->asFunction(); + if (! function) + function = lastVisibleSymbol->enclosingFunction(); - if (functionScope) { + if (function) { LookupContext context(thisDocument, snapshot); - Function *functionDefinition = functionScope->asFunction(); + Function *functionDefinition = function->asFunction(); + ClassOrNamespace *binding = context.lookupType(functionDefinition); + const QList<LookupItem> declarations = context.lookup(functionDefinition->name(), functionDefinition->enclosingScope()); + QList<Symbol *> best; foreach (const LookupItem &r, declarations) { - Symbol *decl = r.declaration(); - // TODO: check decl. - openCppEditorAt(linkToSymbol(decl)); - break; + if (Symbol *decl = r.declaration()) { + if (Function *funTy = decl->type()->asFunctionType()) { + if (funTy->isEqualTo(function) && decl != function && binding == r.binding()) + best.prepend(decl); + else + best.append(decl); + } + } } + if (! best.isEmpty()) + openCppEditorAt(linkToSymbol(best.first())); } else if (lastVisibleSymbol && lastVisibleSymbol->isDeclaration() && lastVisibleSymbol->type()->isFunctionType()) { if (Symbol *def = snapshot.findMatchingDefinition(lastVisibleSymbol)) -- GitLab