From 14848d5e34b9a1740405e7dd435a9ae7791907cb Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Thu, 25 Jun 2009 07:38:48 +0000 Subject: [PATCH] Source hover for specializations, bug 281396 --- .../ui/text/c/hover/CSourceHover.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CSourceHover.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CSourceHover.java index d7678a031db..bbe6e21af32 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CSourceHover.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CSourceHover.java @@ -68,6 +68,7 @@ import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.IVariable; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator; @@ -239,9 +240,15 @@ public class CSourceHover extends AbstractCEditorTextHover { * @throws DOMException if there was an internal problem with the DOM */ private String computeSourceForBinding(IASTTranslationUnit ast, IBinding binding) throws CoreException, DOMException { - IName[] names= findDefinitions(ast, binding); - if (names.length == 0) { - names= findDeclarations(ast, binding); + IName[] names = findDefsOrDecls(ast, binding); + + // in case the binding is a non-explicit specialization we need + // to consider the original binding (bug 281396) + if (names.length == 0 && binding instanceof ICPPSpecialization) { + binding= ((ICPPSpecialization) binding).getSpecializedBinding(); + if (!(binding instanceof IProblemBinding)) { + names= findDefsOrDecls(ast, binding); + } } if (names.length > 0) { for (IName name : names) { @@ -254,6 +261,14 @@ public class CSourceHover extends AbstractCEditorTextHover { return null; } + private IName[] findDefsOrDecls(IASTTranslationUnit ast, IBinding binding) throws CoreException { + IName[] names= findDefinitions(ast, binding); + if (names.length == 0) { + names= findDeclarations(ast, binding); + } + return names; + } + /** * Get the source for the given name from the underlying file. *