mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 09:25:31 +02:00
Bug 403418 - Type Hierarchy view does not show class templates.
This commit is contained in:
parent
6052044cdc
commit
5700e27b7b
4 changed files with 65 additions and 9 deletions
|
@ -37,6 +37,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTFunctionDeclarator;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplate;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPAliasTemplateInstance;
|
||||
|
@ -979,7 +980,9 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
|
|||
return;
|
||||
parentNode = parentNode.getParent();
|
||||
}
|
||||
if (parentNode instanceof ICPPASTBaseSpecifier) {
|
||||
if (name.getPropertyInParent() == ICPPASTBaseSpecifier.NAME ||
|
||||
(name.getPropertyInParent() == ICPPASTTemplateId.TEMPLATE_NAME &&
|
||||
parentNode.getPropertyInParent() == ICPPASTBaseSpecifier.NAME)) {
|
||||
pdomName.setIsBaseSpecifier();
|
||||
} else if (parentNode instanceof ICPPASTUsingDirective) {
|
||||
IASTNode parent= name.getParent();
|
||||
|
|
|
@ -839,4 +839,48 @@ public class CppTypeHierarchyTest extends TypeHierarchyBaseTest {
|
|||
assertEquals(0, item1.getItemCount());
|
||||
checkMethodTable(new String[] {"field1 : T", "method1() : T"});
|
||||
}
|
||||
|
||||
// template<typename T>
|
||||
// class A {
|
||||
// public:
|
||||
// int field1;
|
||||
// int method1();
|
||||
// };
|
||||
// class B : public A<int> {
|
||||
// public:
|
||||
// int field2;
|
||||
// int method2();
|
||||
// };
|
||||
public void testTemplateInstance_403418() throws Exception {
|
||||
String content= getContentsForTest(1)[0].toString();
|
||||
IFile file= createFile(getProject(), "class.cpp", content);
|
||||
waitUntilFileIsIndexed(fIndex, file);
|
||||
CEditor editor= openEditor(file);
|
||||
Tree tree;
|
||||
TreeItem item1, item2;
|
||||
|
||||
editor.selectAndReveal(content.indexOf("A"), 1);
|
||||
openTypeHierarchy(editor);
|
||||
tree= getHierarchyViewer().getTree();
|
||||
|
||||
item1= checkTreeNode(tree, 0, "A");
|
||||
assertEquals(1, tree.getItemCount());
|
||||
getHierarchyViewer().expandAll();
|
||||
|
||||
item2= checkTreeNode(item1, 0, "B");
|
||||
checkMethodTable(new String[] {"field1 : int", "method1() : int"});
|
||||
assertEquals(1, item1.getItemCount());
|
||||
assertEquals(0, item2.getItemCount());
|
||||
|
||||
editor.selectAndReveal(content.indexOf("B"), 1);
|
||||
openTypeHierarchy(editor);
|
||||
tree= getHierarchyViewer().getTree();
|
||||
item1= checkTreeNode(tree, 0, "A");
|
||||
assertEquals(1, tree.getItemCount());
|
||||
|
||||
item2= checkTreeNode(item1, 0, "B");
|
||||
assertEquals(1, item1.getItemCount());
|
||||
assertEquals(0, item2.getItemCount());
|
||||
checkMethodTable(new String[] {"field2 : int", "method2() : int"});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.eclipse.cdt.core.index.IIndexName;
|
|||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
|
||||
import org.eclipse.cdt.internal.core.model.ext.ICElementHandle;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.viewsupport.IndexUI;
|
||||
|
@ -251,9 +252,9 @@ class THGraph {
|
|||
ArrayList<ICElement> memberList= new ArrayList<ICElement>();
|
||||
if (binding instanceof ICPPClassType) {
|
||||
ICPPClassType ct= (ICPPClassType) binding;
|
||||
IBinding[] members= ct.getDeclaredFields();
|
||||
IBinding[] members= ClassTypeHelper.getDeclaredFields(ct, null);
|
||||
addMemberElements(index, members, memberList);
|
||||
members= ct.getDeclaredMethods();
|
||||
members= ClassTypeHelper.getDeclaredMethods(ct, null);
|
||||
addMemberElements(index, members, memberList);
|
||||
} else if (binding instanceof ICompositeType) {
|
||||
ICompositeType ct= (ICompositeType) binding;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2010 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2007, 2013 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
|
||||
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Ed Swartz (Nokia)
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.viewsupport;
|
||||
|
||||
|
@ -59,6 +60,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
|
||||
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.ICPPSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
|
@ -268,12 +270,18 @@ public class IndexUI {
|
|||
}
|
||||
|
||||
public static ICElementHandle[] findRepresentative(IIndex index, IBinding binding) throws CoreException {
|
||||
ICElementHandle[] defs = findAllDefinitions(index, binding);
|
||||
if (defs.length == 0) {
|
||||
ICElementHandle elem = findAnyDeclaration(index, null, binding);
|
||||
if (elem != null) {
|
||||
defs = new ICElementHandle[] { elem };
|
||||
ICElementHandle[] defs;
|
||||
while (true) {
|
||||
defs = findAllDefinitions(index, binding);
|
||||
if (defs.length == 0) {
|
||||
ICElementHandle elem = findAnyDeclaration(index, null, binding);
|
||||
if (elem != null) {
|
||||
defs = new ICElementHandle[] { elem };
|
||||
}
|
||||
}
|
||||
if (defs.length != 0 || !(binding instanceof ICPPSpecialization))
|
||||
break;
|
||||
binding = ((ICPPSpecialization) binding).getSpecializedBinding();
|
||||
}
|
||||
return defs;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue