diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/CElementHandleFactory.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/CElementHandleFactory.java index d551ff4ffe8..7cace59dff6 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/CElementHandleFactory.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/CElementHandleFactory.java @@ -24,10 +24,12 @@ import org.eclipse.cdt.core.dom.ast.ITypedef; import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateScope; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.core.runtime.CoreException; @@ -70,7 +72,12 @@ public class CElementHandleFactory { element= new EnumeratorHandle(parentElement, (IEnumerator) binding); } else if (binding instanceof ICompositeType) { - element= new StructureHandle(parentElement, (ICompositeType) binding); + if (binding instanceof ICPPClassTemplate) { + element= new StructureTemplateHandle(parentElement, (ICompositeType) binding); + } + else { + element= new StructureHandle(parentElement, (ICompositeType) binding); + } } else if (binding instanceof ICPPNamespace) { element= new NamespaceHandle(parentElement, (ICPPNamespace) binding); @@ -93,6 +100,9 @@ public class CElementHandleFactory { if (scopeName == null) { if (scope.getParent() == null) { return tu; + } + if (scope instanceof ICPPTemplateScope) { + return create(tu, scope.getParent()); } return null; // unnamed namespace } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/StructureTemplateHandle.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/StructureTemplateHandle.java new file mode 100644 index 00000000000..18bff3dcf8e --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/StructureTemplateHandle.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2007 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.internal.core.model.ext; + +import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.ICompositeType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.IStructureTemplate; +import org.eclipse.cdt.internal.core.model.Template; + +public class StructureTemplateHandle extends StructureHandle implements IStructureTemplate { + + private Template fTemplate; + + public StructureTemplateHandle(ICElement parent, ICompositeType classTemplate) throws DOMException { + super(parent, classTemplate); + fTemplate= new Template(classTemplate.getName()); + if (classTemplate instanceof ICPPClassTemplate) { + ICPPClassTemplate ct= (ICPPClassTemplate) classTemplate; + ICPPTemplateParameter[] tps= ct.getTemplateParameters(); + String[] types= new String[tps.length]; + for (int i = 0; i < tps.length; i++) { + ICPPTemplateParameter tp = tps[i]; + types[i]= tp.getName(); + } + fTemplate.setTemplateParameterTypes(types); + } + } + + public int getNumberOfTemplateParameters() { + return fTemplate.getNumberOfTemplateParameters(); + } + + public String[] getTemplateParameterTypes() { + return fTemplate.getTemplateParameterTypes(); + } + + public String getTemplateSignature() throws CModelException { + return fTemplate.getTemplateSignature(); + } +} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/CppTypeHierarchyTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/CppTypeHierarchyTest.java index 8c9caa06829..a3f3a4a87d9 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/CppTypeHierarchyTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/CppTypeHierarchyTest.java @@ -440,4 +440,27 @@ public class CppTypeHierarchyTest extends TypeHierarchyBaseTest { checkMethodTable(new String[] {"field4", "method4()"}); } + // template class SimpleTemplate { + // public: + // T field1; + // T method1(); + // }; + public void _testTemplatesNoInheritance() throws Exception { + String content= getContentsForTest(1)[0].toString(); + IFile file= createFile(getProject(), "simpleTemplate.cpp", content); + waitForIndexer(fIndex, file, INDEXER_WAIT_TIME); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + CEditor editor= (CEditor) IDE.openEditor(page, file); + Tree tree; + TreeItem item1, item2, item3, item4; + + editor.selectAndReveal(content.indexOf("SimpleTemplate"), 1); + openTypeHierarchy(editor); + tree= getHierarchyViewer().getTree(); + + item1= checkTreeNode(tree, 0, "SimpleTemplate"); + assertEquals(1, tree.getItemCount()); + assertEquals(0, item1.getItemCount()); + checkMethodTable(new String[] {"field1", "method1()"}); + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/THGraph.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/THGraph.java index e6d7220641f..7f397363a0d 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/THGraph.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/THGraph.java @@ -290,4 +290,8 @@ class THGraph { } } } + + public boolean isTrivial() { + return fNodes.size() < 2; + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/THHierarchyModel.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/THHierarchyModel.java index daad179be2e..10cce0cdb8e 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/THHierarchyModel.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/THHierarchyModel.java @@ -359,7 +359,9 @@ class THHierarchyModel { } private boolean isImplementor(ICElement element) { - if (element == null || fSelectedMember == null || fMemberSignatureToSelect == null) { + if (element == null + || fSelectedMember == null || fMemberSignatureToSelect == null + || fGraph.isTrivial()) { return false; } THGraphNode gnode= fGraph.getNode(element); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/TypeHierarchyUI.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/TypeHierarchyUI.java index 355fb5f6d90..3a8280106fd 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/TypeHierarchyUI.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/TypeHierarchyUI.java @@ -296,6 +296,12 @@ public class TypeHierarchyUI { case ICElement.C_UNION_DECLARATION: case ICElement.C_ENUMERATION: case ICElement.C_TYPEDEF: +// case ICElement.C_TEMPLATE_CLASS: +// case ICElement.C_TEMPLATE_CLASS_DECLARATION: +// case ICElement.C_TEMPLATE_STRUCT: +// case ICElement.C_TEMPLATE_STRUCT_DECLARATION: +// case ICElement.C_TEMPLATE_UNION: +// case ICElement.C_TEMPLATE_UNION_DECLARATION: return true; } return false;