diff --git a/core/org.eclipse.cdt.ui.tests/resources/addInclude/Template_306670.cpp b/core/org.eclipse.cdt.ui.tests/resources/addInclude/Template_306670.cpp new file mode 100644 index 00000000000..0b1056c30ee --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/resources/addInclude/Template_306670.cpp @@ -0,0 +1,3 @@ +void test() { + func306670(1); +} diff --git a/core/org.eclipse.cdt.ui.tests/resources/addInclude/Template_306670.cpp.expected b/core/org.eclipse.cdt.ui.tests/resources/addInclude/Template_306670.cpp.expected new file mode 100644 index 00000000000..01482ac274f --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/resources/addInclude/Template_306670.cpp.expected @@ -0,0 +1,4 @@ +#include "Template_306670.h" +void test() { + func306670(1); +} diff --git a/core/org.eclipse.cdt.ui.tests/resources/addInclude/Template_306670.h b/core/org.eclipse.cdt.ui.tests/resources/addInclude/Template_306670.h new file mode 100644 index 00000000000..158b91fe01a --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/resources/addInclude/Template_306670.h @@ -0,0 +1,4 @@ +template void func306670(T) {} +void bla() { + func306670(1); // make sure the instance is in the index. +} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/AddIncludeTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/AddIncludeTest.java index 6235b28f14d..9b092ee6a27 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/AddIncludeTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/AddIncludeTest.java @@ -144,4 +144,9 @@ public class AddIncludeTest extends TestCase { select("XXX"); assertAddIncludeResult(); } + + public void testTemplate_306670() throws Exception { + select("func306670"); + assertAddIncludeResult(); + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAction.java index af45480fba1..38bbdb468f2 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAction.java @@ -22,6 +22,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; +import java.util.List; import java.util.Map; import org.eclipse.core.resources.IProject; @@ -55,7 +56,6 @@ import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IFunction; -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.cpp.ICPPASTQualifiedName; @@ -64,6 +64,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndexBinding; @@ -231,12 +232,23 @@ public class AddIncludeOnSelectionAction extends TextEditorAction { } final Map candidatesMap= new HashMap(); - IIndex index = ast.getIndex(); + final IIndex index = ast.getIndex(); final IndexFilter filter = IndexFilter.getDeclaredBindingFilter(ast.getLinkage().getLinkageID(), false); - IIndexBinding[] bindings = - binding instanceof IIndexBinding && !(binding instanceof IProblemBinding) ? - new IIndexBinding[] { (IIndexBinding) binding } : - index.findBindings(nameChars, false, filter, new NullProgressMonitor()); + + List bindings = new ArrayList(); + IIndexBinding adaptedBinding= index.adaptBinding(binding); + if (adaptedBinding == null) { + bindings.addAll(Arrays.asList(index.findBindings(nameChars, false, filter, new NullProgressMonitor()))); + } else { + bindings.add(adaptedBinding); + while (adaptedBinding instanceof ICPPSpecialization) { + adaptedBinding= index.adaptBinding(((ICPPSpecialization) adaptedBinding).getSpecializedBinding()); + if (adaptedBinding != null) { + bindings.add(adaptedBinding); + } + } + } + for (IIndexBinding indexBinding : bindings) { // Replace ctor with the class itself. @@ -258,6 +270,8 @@ public class AddIncludeOnSelectionAction extends TextEditorAction { for (IIndexName definition : definitions) { considerForInclusion(definition, indexBinding, index, candidatesMap); } + if (definitions.length > 0 && adaptedBinding != null) + break; } } IIndexMacro[] macros = index.findMacros(nameChars, filter, new NullProgressMonitor());