mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 12:55:40 +02:00
Type Hierarchy: Prepares support for class templates.
This commit is contained in:
parent
f6d76dc15d
commit
dedbb3093d
6 changed files with 100 additions and 2 deletions
|
@ -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.IVariable;
|
||||||
import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
|
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.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.ICPPClassType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
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.ICPPNamespace;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
|
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.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
@ -70,7 +72,12 @@ public class CElementHandleFactory {
|
||||||
element= new EnumeratorHandle(parentElement, (IEnumerator) binding);
|
element= new EnumeratorHandle(parentElement, (IEnumerator) binding);
|
||||||
}
|
}
|
||||||
else if (binding instanceof ICompositeType) {
|
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) {
|
else if (binding instanceof ICPPNamespace) {
|
||||||
element= new NamespaceHandle(parentElement, (ICPPNamespace) binding);
|
element= new NamespaceHandle(parentElement, (ICPPNamespace) binding);
|
||||||
|
@ -93,6 +100,9 @@ public class CElementHandleFactory {
|
||||||
if (scopeName == null) {
|
if (scopeName == null) {
|
||||||
if (scope.getParent() == null) {
|
if (scope.getParent() == null) {
|
||||||
return tu;
|
return tu;
|
||||||
|
}
|
||||||
|
if (scope instanceof ICPPTemplateScope) {
|
||||||
|
return create(tu, scope.getParent());
|
||||||
}
|
}
|
||||||
return null; // unnamed namespace
|
return null; // unnamed namespace
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -440,4 +440,27 @@ public class CppTypeHierarchyTest extends TypeHierarchyBaseTest {
|
||||||
checkMethodTable(new String[] {"field4", "method4()"});
|
checkMethodTable(new String[] {"field4", "method4()"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// template <typename T> 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()"});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -290,4 +290,8 @@ class THGraph {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isTrivial() {
|
||||||
|
return fNodes.size() < 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -359,7 +359,9 @@ class THHierarchyModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isImplementor(ICElement element) {
|
private boolean isImplementor(ICElement element) {
|
||||||
if (element == null || fSelectedMember == null || fMemberSignatureToSelect == null) {
|
if (element == null
|
||||||
|
|| fSelectedMember == null || fMemberSignatureToSelect == null
|
||||||
|
|| fGraph.isTrivial()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
THGraphNode gnode= fGraph.getNode(element);
|
THGraphNode gnode= fGraph.getNode(element);
|
||||||
|
|
|
@ -296,6 +296,12 @@ public class TypeHierarchyUI {
|
||||||
case ICElement.C_UNION_DECLARATION:
|
case ICElement.C_UNION_DECLARATION:
|
||||||
case ICElement.C_ENUMERATION:
|
case ICElement.C_ENUMERATION:
|
||||||
case ICElement.C_TYPEDEF:
|
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 true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue