diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITemplate.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITemplate.java
index 94d302066d5..44fc8330578 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITemplate.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITemplate.java
@@ -7,10 +7,13 @@
*
* Contributors:
* Rational Software - initial implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.model;
/**
+ * The interface is used to model, class or function templates and their partial or
+ * explicit specializations.
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*/
@@ -21,6 +24,13 @@ public interface ITemplate {
*/
String[] getTemplateParameterTypes();
+ /**
+ * Returns the template arguments in a printable format. For templates that are no specialization,
+ * this will return the names of the template parameters.
+ * @since 5.2
+ */
+ String[] getTemplateArguments();
+
/**
* Returns the template signature
* The signature depends on the type of template.
@@ -35,7 +45,6 @@ public interface ITemplate {
/**
* Returns the number of template parameters
- * @return int
*/
int getNumberOfTemplateParameters();
}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/util/CElementBaseLabels.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/util/CElementBaseLabels.java
index fe99de3cbc4..bc6798d8366 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/util/CElementBaseLabels.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/util/CElementBaseLabels.java
@@ -126,6 +126,13 @@ public class CElementBaseLabels {
*/
public final static int T_FULLY_QUALIFIED= 1 << 13;
+ /**
+ * Instances and specializations are qualified with arguments, templates with template parameter names.
+ * The flag overrides {@link #TEMPLATE_PARAMETERS}.
+ * @since 5.2
+ */
+ public final static int TEMPLATE_ARGUMENTS= 1 << 14;
+
/**
* Append base class specifications to type names.
* e.g. MyClass : public BaseClass
@@ -358,7 +365,7 @@ public class CElementBaseLabels {
if( getFlag( flags, M_FULLY_QUALIFIED ) ){
ICElement parent = method.getParent();
if (parent != null && parent.exists() && !(parent instanceof ITranslationUnit)) {
- getTypeLabel( parent, T_FULLY_QUALIFIED, buf );
+ getTypeLabel( parent, T_FULLY_QUALIFIED | (flags & TEMPLATE_ARGUMENTS), buf );
buf.append( "::" ); //$NON-NLS-1$
}
}
@@ -417,7 +424,7 @@ public class CElementBaseLabels {
// post qualification
if( getFlag(flags, M_POST_QUALIFIED)) {
buf.append( CONCAT_STRING );
- getTypeLabel( method.getParent(), T_FULLY_QUALIFIED, buf );
+ getTypeLabel( method.getParent(), T_FULLY_QUALIFIED | (flags & TEMPLATE_ARGUMENTS), buf );
}
if( getFlag(flags, MF_POST_FILE_QUALIFIED)) {
IPath path= method.getPath();
@@ -446,19 +453,25 @@ public class CElementBaseLabels {
}
private static void getTemplateParameters(ITemplate template, int flags, StringBuffer buf) {
- if (getFlag(flags, TEMPLATE_PARAMETERS)) {
- String[] types = template.getTemplateParameterTypes();
- buf.append('<');
- if (types != null) {
- for (int i= 0; i < types.length; i++) {
- if (i > 0) {
- buf.append( ',' );
- }
- buf.append( types[i] );
- }
- }
- buf.append('>');
+ String[] args= null;
+ if (getFlag(flags, TEMPLATE_ARGUMENTS)) {
+ args = template.getTemplateArguments();
+ } else if (getFlag(flags, TEMPLATE_PARAMETERS)) {
+ args= template.getTemplateParameterTypes();
+ } else {
+ return;
}
+
+ buf.append('<');
+ if (args != null) {
+ for (int i= 0; i < args.length; i++) {
+ if (i > 0) {
+ buf.append( ',' );
+ }
+ buf.append( args[i] );
+ }
+ }
+ buf.append('>');
}
/**
@@ -479,7 +492,7 @@ public class CElementBaseLabels {
if( getFlag( flags, F_FULLY_QUALIFIED ) ){
ICElement parent = field.getParent();
if (parent != null && parent.exists()) {
- getTypeLabel( parent, T_FULLY_QUALIFIED, buf );
+ getTypeLabel( parent, T_FULLY_QUALIFIED | (flags & TEMPLATE_PARAMETERS), buf );
buf.append( "::" ); //$NON-NLS-1$
}
}
@@ -498,7 +511,7 @@ public class CElementBaseLabels {
// post qualification
if( getFlag(flags, F_POST_QUALIFIED)) {
buf.append( CONCAT_STRING );
- getTypeLabel( field.getParent(), T_FULLY_QUALIFIED, buf );
+ getTypeLabel( field.getParent(), T_FULLY_QUALIFIED | (flags & TEMPLATE_PARAMETERS), buf );
}
if( getFlag(flags, MF_POST_FILE_QUALIFIED)) {
IPath path= field.getPath();
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionTemplate.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionTemplate.java
index 4280378cd70..7767d79bb40 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionTemplate.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionTemplate.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2002, 2008 IBM Corporation and others.
+ * Copyright (c) 2002, 2009 IBM Corporation 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
@@ -33,11 +33,15 @@ public class FunctionTemplate extends Function implements IFunctionTemplate {
return fTemplate.getTemplateParameterTypes();
}
+ public String[] getTemplateArguments() {
+ return fTemplate.getTemplateArguments();
+ }
+
/**
* Sets the template parameter types.
*/
public void setTemplateParameterTypes(String[] templateParameterTypes) {
- fTemplate.setTemplateParameterTypes(templateParameterTypes);
+ fTemplate.setTemplateInfo(templateParameterTypes, null);
}
/**
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionTemplateDeclaration.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionTemplateDeclaration.java
index e8cf11999df..4f6c18ba4a3 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionTemplateDeclaration.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/FunctionTemplateDeclaration.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005 QnX Software Systems and others.
+ * Copyright (c) 2005, 2009 QnX Software Systems 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
@@ -28,6 +28,10 @@ public class FunctionTemplateDeclaration extends FunctionDeclaration implements
return fTemplate.getTemplateParameterTypes();
}
+ public String[] getTemplateArguments() {
+ return fTemplate.getTemplateArguments();
+ }
+
public String getTemplateSignature() throws CModelException {
StringBuffer sig = new StringBuffer(fTemplate.getTemplateSignature());
sig.append(this.getParameterClause());
@@ -52,7 +56,7 @@ public class FunctionTemplateDeclaration extends FunctionDeclaration implements
* Sets the template parameter types.
*/
public void setTemplateParameterTypes(String[] templateParameterTypes) {
- fTemplate.setTemplateParameterTypes(templateParameterTypes);
+ fTemplate.setTemplateInfo(templateParameterTypes, null);
}
}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MethodTemplate.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MethodTemplate.java
index 96476348f6a..460a7128bfe 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MethodTemplate.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MethodTemplate.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2002, 2008 IBM Corporation and others.
+ * Copyright (c) 2002, 2009 IBM Corporation 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
@@ -33,12 +33,16 @@ public class MethodTemplate extends Method implements IMethodTemplate {
return fTemplate.getTemplateParameterTypes();
}
+ public String[] getTemplateArguments() {
+ return fTemplate.getTemplateArguments();
+ }
+
/**
* Sets the fParameterTypes.
* @param templateParameterTypes The template parameter types to set
*/
public void setTemplateParameterTypes(String[] templateParameterTypes) {
- fTemplate.setTemplateParameterTypes(templateParameterTypes);
+ fTemplate.setTemplateInfo(templateParameterTypes, null);
}
/**
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MethodTemplateDeclaration.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MethodTemplateDeclaration.java
index 4bb4577e63a..083f5c0f5db 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MethodTemplateDeclaration.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/MethodTemplateDeclaration.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005 QnX Software Systems and others.
+ * Copyright (c) 2005, 2009 QnX Software Systems 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
@@ -28,6 +28,10 @@ public class MethodTemplateDeclaration extends MethodDeclaration implements IMet
return fTemplate.getTemplateParameterTypes();
}
+ public String[] getTemplateArguments() {
+ return fTemplate.getTemplateArguments();
+ }
+
public String getTemplateSignature() throws CModelException {
StringBuffer sig = new StringBuffer(fTemplate.getTemplateSignature());
sig.append(this.getParameterClause());
@@ -54,7 +58,7 @@ public class MethodTemplateDeclaration extends MethodDeclaration implements IMet
* @param templateParameterTypes The template parameter types to set
*/
public void setTemplateParameterTypes(String[] templateParameterTypes) {
- fTemplate.setTemplateParameterTypes(templateParameterTypes);
+ fTemplate.setTemplateInfo(templateParameterTypes, null);
}
}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/StructureTemplate.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/StructureTemplate.java
index f47582b1515..a2460e76eb5 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/StructureTemplate.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/StructureTemplate.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2002, 2008 IBM Corporation and others.
+ * Copyright (c) 2002, 2009 IBM Corporation 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
@@ -31,12 +31,16 @@ public class StructureTemplate extends Structure implements IStructureTemplate {
return fTemplate.getTemplateParameterTypes();
}
+ public String[] getTemplateArguments() {
+ return fTemplate.getTemplateArguments();
+ }
+
/**
* Sets the fParameterTypes.
* @param templateParameterTypes The template parameter types to set
*/
public void setTemplateParameterTypes(String[] templateParameterTypes) {
- fTemplate.setTemplateParameterTypes(templateParameterTypes);
+ fTemplate.setTemplateInfo(templateParameterTypes, null);
}
/**
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/StructureTemplateDeclaration.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/StructureTemplateDeclaration.java
index f3ba748418f..5c20c5de040 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/StructureTemplateDeclaration.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/StructureTemplateDeclaration.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2008 QnX Software Systems and others.
+ * Copyright (c) 2005, 2009 QnX Software Systems 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
@@ -29,8 +29,12 @@ public class StructureTemplateDeclaration extends StructureDeclaration implement
return fTemplate.getTemplateParameterTypes();
}
+ public String[] getTemplateArguments() {
+ return fTemplate.getTemplateArguments();
+ }
+
public void setTemplateParameterTypes(String[] templateParameterTypes) {
- fTemplate.setTemplateParameterTypes(templateParameterTypes);
+ fTemplate.setTemplateInfo(templateParameterTypes, null);
}
public String getTemplateSignature() throws CModelException {
@@ -46,9 +50,9 @@ public class StructureTemplateDeclaration extends StructureDeclaration implement
super.getHandleMemento(buff);
if (fTemplate.getNumberOfTemplateParameters() > 0) {
final String[] parameterTypes= fTemplate.getTemplateParameterTypes();
- for (int i = 0; i < parameterTypes.length; i++) {
+ for (String parameterType : parameterTypes) {
buff.append(CEM_PARAMETER);
- escapeMementoName(buff, parameterTypes[i]);
+ escapeMementoName(buff, parameterType);
}
}
}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Template.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Template.java
index 8c2e14481eb..56b1c162177 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Template.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Template.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005 QnX Software Systems and others.
+ * Copyright (c) 2005, 2009 QnX Software Systems 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
@@ -7,21 +7,22 @@
*
* Contributors:
* Qnx Software Systems - initial API and implementation
+ * Markus Schorn (Wind River Systems)
*******************************************************************************/
-
package org.eclipse.cdt.internal.core.model;
import org.eclipse.cdt.core.model.ITemplate;
public class Template implements ITemplate {
-
- protected static final String[] fgEmptyList= new String[] {};
- protected String[] templateParameterTypes;
+ protected static final String[] fgEmptyList= {};
+ protected String[] fTemplateParameterTypes;
+ protected String[] fTemplateArgs;
protected String fName;
public Template(String name) {
fName = name;
- templateParameterTypes= fgEmptyList;
+ fTemplateParameterTypes= fgEmptyList;
+ fTemplateArgs= fgEmptyList;
}
/**
* Returns the parameterTypes.
@@ -29,22 +30,26 @@ public class Template implements ITemplate {
* @return String[]
*/
public String[] getTemplateParameterTypes() {
- return templateParameterTypes;
+ return fTemplateParameterTypes;
+ }
+
+ public String[] getTemplateArguments() {
+ return fTemplateArgs;
}
/**
- * Sets the fParameterTypes.
- * @param templateParameterTypes The template parameter types to set
+ * Sets the parameter types and template arguments.
*/
- public void setTemplateParameterTypes(String[] templateParameterTypes) {
- this.templateParameterTypes = templateParameterTypes;
+ public void setTemplateInfo(String[] templateParameterTypes, String[] args) {
+ if (templateParameterTypes != null)
+ fTemplateParameterTypes = templateParameterTypes;
+ if (args != null) {
+ fTemplateArgs= args;
+ }
}
- /**
- * @see org.eclipse.cdt.core.model.ITemplate#getNumberOfTemplateParameters()
- */
public int getNumberOfTemplateParameters() {
- return templateParameterTypes == null ? 0 : templateParameterTypes.length;
+ return fTemplateParameterTypes == null ? 0 : fTemplateParameterTypes.length;
}
/**
@@ -68,5 +73,4 @@ public class Template implements ITemplate {
}
return sig.toString();
}
-
}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/VariableTemplate.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/VariableTemplate.java
index 1179ac4b0af..0cac69111da 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/VariableTemplate.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/VariableTemplate.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2002, 2006 IBM Corporation and others.
+ * Copyright (c) 2002, 2009 IBM Corporation 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
@@ -37,6 +37,10 @@ public class VariableTemplate extends Variable implements ITemplate {
return templateParameterTypes;
}
+ public String[] getTemplateArguments() {
+ return fgEmptyList;
+ }
+
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ITemplate#setTemplateParameterTypes(java.lang.String[])
*/
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 7e5a0a33c41..17ae8b0b54b 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
@@ -22,9 +22,14 @@ import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IVariable;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
+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.ICPPTemplateInstance;
import org.eclipse.cdt.core.index.IIndexMacro;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ITranslationUnit;
@@ -73,11 +78,20 @@ public class CElementHandleFactory {
element= definition
? new MethodHandle(parentElement, (ICPPMethod) binding)
: new MethodDeclarationHandle(parentElement, (ICPPMethod) binding);
- }
- else if (binding instanceof IFunction) {
- element= definition
- ? new FunctionHandle(parentElement, (IFunction) binding)
- : new FunctionDeclarationHandle(parentElement, (IFunction) binding);
+ } else if (binding instanceof IFunction) {
+ if (binding instanceof ICPPTemplateInstance) {
+ element= definition
+ ? new FunctionTemplateHandle(parentElement, (ICPPTemplateInstance) binding)
+ : new FunctionTemplateDeclarationHandle(parentElement, (ICPPTemplateInstance) binding);
+ } else if (binding instanceof ICPPFunctionTemplate) {
+ element= definition
+ ? new FunctionTemplateHandle(parentElement, (ICPPFunctionTemplate) binding)
+ : new FunctionTemplateDeclarationHandle(parentElement, (ICPPFunctionTemplate) binding);
+ } else {
+ element= definition
+ ? new FunctionHandle(parentElement, (IFunction) binding)
+ : new FunctionDeclarationHandle(parentElement, (IFunction) binding);
+ }
}
else if (binding instanceof IField) {
element= new FieldHandle(parentElement, (IField) binding);
@@ -95,12 +109,7 @@ public class CElementHandleFactory {
element= new EnumeratorHandle(parentElement, (IEnumerator) binding);
}
else if (binding instanceof ICompositeType) {
- if (binding instanceof ICPPClassTemplate) {
- element= new StructureTemplateHandle(parentElement, (ICompositeType) binding);
- }
- else {
- element= new StructureHandle(parentElement, (ICompositeType) binding);
- }
+ element= createHandleForComposite(parentElement, (ICompositeType) binding);
}
else if (binding instanceof ICPPNamespace) {
element= new NamespaceHandle(parentElement, (ICPPNamespace) binding);
@@ -139,9 +148,27 @@ public class CElementHandleFactory {
if (parentBinding instanceof ICompositeType) {
ICElement grandParent= createParent(tu, parentBinding);
if (grandParent != null) {
- return new StructureHandle(grandParent, (ICompositeType) parentBinding);
+ return createHandleForComposite(grandParent, (ICompositeType) parentBinding);
}
}
return null;
}
+
+ private static CElementHandle createHandleForComposite(ICElement parent, ICompositeType classBinding)
+ throws DOMException {
+ if (classBinding instanceof ICPPClassTemplatePartialSpecialization) {
+ return new StructureTemplateHandle(parent, (ICPPClassTemplatePartialSpecialization) classBinding);
+ }
+ if (classBinding instanceof ICPPClassTemplate) {
+ return new StructureTemplateHandle(parent, (ICPPClassTemplate) classBinding);
+ }
+ if (classBinding instanceof ICPPClassSpecialization) {
+ ICPPClassSpecialization spec= (ICPPClassSpecialization) classBinding;
+ ICPPClassType orig= spec.getSpecializedBinding();
+ if (orig instanceof ICPPClassTemplate) {
+ return new StructureTemplateHandle(parent, (ICPPClassSpecialization) classBinding, (ICPPClassTemplate) orig);
+ }
+ }
+ return new StructureHandle(parent, classBinding);
+ }
}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/FunctionTemplateDeclarationHandle.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/FunctionTemplateDeclarationHandle.java
new file mode 100644
index 00000000000..0b8b97eb01a
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/FunctionTemplateDeclarationHandle.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.ASTTypeUtil;
+import org.eclipse.cdt.core.dom.ast.DOMException;
+import org.eclipse.cdt.core.dom.ast.IFunction;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
+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.IFunctionTemplateDeclaration;
+import org.eclipse.cdt.internal.core.model.Template;
+
+public class FunctionTemplateDeclarationHandle extends FunctionDeclarationHandle implements IFunctionTemplateDeclaration {
+ Template fTemplate;
+
+ public FunctionTemplateDeclarationHandle(ICElement parent, ICPPFunctionTemplate func) throws DOMException {
+ this(parent, ICElement.C_TEMPLATE_FUNCTION_DECLARATION, func);
+ }
+
+ public FunctionTemplateDeclarationHandle(ICElement parent, ICPPTemplateInstance func) throws DOMException {
+ this(parent, ICElement.C_TEMPLATE_FUNCTION_DECLARATION, func);
+ }
+
+ protected FunctionTemplateDeclarationHandle(ICElement parent, int type, ICPPFunctionTemplate func) throws DOMException {
+ super(parent, type, func);
+ fTemplate= new Template(func.getName());
+ ICPPTemplateParameter[] tpars = func.getTemplateParameters();
+ String[] args= new String[tpars.length];
+ for (int i = 0; i < args.length; i++) {
+ args[i]= tpars[i].getName();
+ }
+ fTemplate.setTemplateInfo(null, args);
+ }
+
+ protected FunctionTemplateDeclarationHandle(ICElement parent, int type, ICPPTemplateInstance func) throws DOMException {
+ super(parent, type, (IFunction) func);
+ fTemplate= new Template(func.getName());
+ ICPPTemplateArgument[] targs = func.getTemplateArguments();
+ String[] args= new String[targs.length];
+ for (int i = 0; i < args.length; i++) {
+ args[i]= ASTTypeUtil.getArgumentString(targs[i], false);
+ }
+ fTemplate.setTemplateInfo(null, args);
+ }
+
+ public String[] getTemplateArguments() {
+ return fTemplate.getTemplateArguments();
+ }
+
+ 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.core/model/org/eclipse/cdt/internal/core/model/ext/FunctionTemplateHandle.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/FunctionTemplateHandle.java
new file mode 100644
index 00000000000..8a49d4f303a
--- /dev/null
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ext/FunctionTemplateHandle.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.cpp.ICPPFunctionTemplate;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.IFunctionTemplate;
+
+public class FunctionTemplateHandle extends FunctionTemplateDeclarationHandle implements IFunctionTemplate {
+
+ public FunctionTemplateHandle(ICElement parent, ICPPFunctionTemplate func) throws DOMException {
+ super(parent, ICElement.C_TEMPLATE_FUNCTION, func);
+ }
+ public FunctionTemplateHandle(ICElement parent, ICPPTemplateInstance func) throws DOMException {
+ super(parent, ICElement.C_TEMPLATE_FUNCTION, func);
+ }
+
+}
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
index 0fbe5656862..f19162f112f 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
+ * Copyright (c) 2007, 2009 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
@@ -9,13 +9,16 @@
* Markus Schorn - initial API and implementation
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
-
package org.eclipse.cdt.internal.core.model.ext;
+import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.DOMException;
-import org.eclipse.cdt.core.dom.ast.ICompositeType;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplatePartialSpecialization;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameterMap;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IStructureTemplate;
@@ -25,19 +28,40 @@ public class StructureTemplateHandle extends StructureHandle implements IStructu
private Template fTemplate;
- public StructureTemplateHandle(ICElement parent, ICompositeType classTemplate) throws DOMException {
+ public StructureTemplateHandle(ICElement parent, ICPPClassTemplate 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);
+ ICPPTemplateParameter[] tpars = classTemplate.getTemplateParameters();
+ String[] args= new String[tpars.length];
+ for (int i = 0; i < args.length; i++) {
+ args[i]= tpars[i].getName();
}
+ fTemplate.setTemplateInfo(null, args);
+ }
+
+ public StructureTemplateHandle(ICElement parent, ICPPClassTemplatePartialSpecialization classTemplate) throws DOMException {
+ super(parent, classTemplate);
+ fTemplate= new Template(classTemplate.getName());
+ ICPPTemplateArgument[] targs = classTemplate.getTemplateArguments();
+ String[] args= new String[targs.length];
+ for (int i = 0; i < args.length; i++) {
+ args[i]= ASTTypeUtil.getArgumentString(targs[i], false);
+ }
+ fTemplate.setTemplateInfo(null, args);
+ }
+
+ public StructureTemplateHandle(ICElement parent, ICPPClassSpecialization classBinding, ICPPClassTemplate ct) throws DOMException {
+ super(parent, classBinding);
+ fTemplate= new Template(classBinding.getName());
+ ICPPTemplateParameterMap map = classBinding.getTemplateParameterMap();
+ ICPPTemplateParameter[] tpars = ct.getTemplateParameters();
+ String[] args= new String[tpars.length];
+ for (int i = 0; i < tpars.length; i++) {
+ ICPPTemplateParameter par = tpars[i];
+ ICPPTemplateArgument arg = map.getArgument(par);
+ args[i]= arg == null ? par.getName() : ASTTypeUtil.getArgumentString(arg, false);
+ }
+ fTemplate.setTemplateInfo(null, args);
}
public int getNumberOfTemplateParameters() {
@@ -48,6 +72,10 @@ public class StructureTemplateHandle extends StructureHandle implements IStructu
return fTemplate.getTemplateParameterTypes();
}
+ public String[] getTemplateArguments() {
+ return fTemplate.getTemplateArguments();
+ }
+
public String getTemplateSignature() throws CModelException {
return fTemplate.getTemplateSignature();
}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CallHierarchyBugs.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CallHierarchyBugs.java
index 4b58c04e568..639a75938aa 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CallHierarchyBugs.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CallHierarchyBugs.java
@@ -263,7 +263,7 @@ public class CallHierarchyBugs extends CallHierarchyBaseTest {
int idx = content.indexOf("Foo(3)");
editor.selectAndReveal(idx, 0);
openCallHierarchy(editor, true);
- Tree chTree= checkTreeNode(ch, 0, "CSome::Foo(const int &)").getParent();
+ Tree chTree= checkTreeNode(ch, 0, "CSome::Foo(const int &)").getParent();
TreeItem item= checkTreeNode(chTree, 0, 0, "test()");
checkTreeNode(chTree, 0, 1, null);
}
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CppCallHierarchyTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CppCallHierarchyTest.java
index 4feaa41b9ff..8ca646a3443 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CppCallHierarchyTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CppCallHierarchyTest.java
@@ -375,4 +375,94 @@ public class CppCallHierarchyTest extends CallHierarchyBaseTest {
checkTreeNode(node, 0, "cfunc()");
checkTreeNode(node, 1, null);
}
+
+ // template void f(T t) {}
+ // template<> void f(int t) {}
+ //
+ // template class CT {
+ // public:
+ // void m() {};
+ // };
+ // template class CT {
+ // public:
+ // void m() {};
+ // };
+ // template<> class CT {
+ // public:
+ // void m() {}
+ // };
+ //
+ // void testint() {
+ // CT ci;
+ // ci.m();
+ // f(1);
+ // }
+ //
+ // void testintptr() {
+ // CT ci;
+ // ci.m();
+ // int i= 1;
+ // f(&i);
+ // }
+ //
+ // void testchar() {
+ // CT ci;
+ // ci.m();
+ // f('1');
+ // }
+ public void testTemplates() throws Exception {
+ StringBuffer[] content= getContentsForTest(1);
+ String source = content[0].toString();
+ IFile file= createFile(getProject(), "testTemplates.cpp", source);
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ CEditor editor= openEditor(file);
+ waitForIndexer(fIndex, file, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
+ CCorePlugin.getIndexManager().joinIndexer(INDEXER_WAIT_TIME, NPM);
+
+ int pos= source.indexOf("f(");
+ editor.selectAndReveal(pos, 1);
+ openCallHierarchy(editor, true);
+ Tree tree = getCHTreeViewer().getTree();
+
+ checkTreeNode(tree, 0, "f(T)");
+ checkTreeNode(tree, 0, 0, "testintptr()");
+ checkTreeNode(tree, 0, 1, "testint()");
+ checkTreeNode(tree, 0, 2, null);
+
+ pos= source.indexOf("f(", pos+1);
+ editor.selectAndReveal(pos, 1);
+ openCallHierarchy(editor, true);
+ tree = getCHTreeViewer().getTree();
+
+ checkTreeNode(tree, 0, "f(char)");
+ checkTreeNode(tree, 0, 0, "testchar()");
+ checkTreeNode(tree, 0, 1, null);
+
+ pos= source.indexOf("m(", pos+1);
+ editor.selectAndReveal(pos, 1);
+ openCallHierarchy(editor, true);
+ tree = getCHTreeViewer().getTree();
+
+ checkTreeNode(tree, 0, "CT::m()");
+ checkTreeNode(tree, 0, 0, "testint()");
+ checkTreeNode(tree, 0, 1, null);
+
+ pos= source.indexOf("m(", pos+1);
+ editor.selectAndReveal(pos, 1);
+ openCallHierarchy(editor, true);
+ tree = getCHTreeViewer().getTree();
+
+ checkTreeNode(tree, 0, "CT::m()");
+ checkTreeNode(tree, 0, 0, "testintptr()");
+ checkTreeNode(tree, 0, 1, null);
+
+ pos= source.indexOf("m(", pos+1);
+ editor.selectAndReveal(pos, 1);
+ openCallHierarchy(editor, true);
+ tree = getCHTreeViewer().getTree();
+
+ checkTreeNode(tree, 0, "CT::m()");
+ checkTreeNode(tree, 0, 0, "testchar()");
+ checkTreeNode(tree, 0, 1, null);
+ }
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHLabelProvider.java
index 7a892d1a788..ffd203478af 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHLabelProvider.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHLabelProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
+ * Copyright (c) 2006, 2009 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
@@ -11,7 +11,6 @@
package org.eclipse.cdt.internal.ui.callhierarchy;
import java.util.HashMap;
-import java.util.Iterator;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.IColorProvider;
@@ -33,10 +32,11 @@ import org.eclipse.cdt.internal.ui.viewsupport.CUILabelProvider;
import org.eclipse.cdt.internal.ui.viewsupport.ImageImageDescriptor;
public class CHLabelProvider extends LabelProvider implements IColorProvider {
- private final static int LABEL_OPTIONS_SIMPLE= CElementBaseLabels.ALL_FULLY_QUALIFIED | CElementBaseLabels.M_PARAMETER_TYPES;
+ private final static int LABEL_OPTIONS_SIMPLE = CElementBaseLabels.ALL_FULLY_QUALIFIED
+ | CElementBaseLabels.M_PARAMETER_TYPES | CElementBaseLabels.TEMPLATE_ARGUMENTS;
private final static int LABEL_OPTIONS_SHOW_FILES= LABEL_OPTIONS_SIMPLE | CElementBaseLabels.MF_POST_FILE_QUALIFIED;
- private CUILabelProvider fCLabelProvider= new CUILabelProvider(LABEL_OPTIONS_SIMPLE, 0);
+ private CUILabelProvider fCLabelProvider= new CUILabelProvider(LABEL_OPTIONS_SIMPLE, CElementImageProvider.OVERLAY_ICONS);
private CHContentProvider fContentProvider;
private HashMap fCachedImages= new HashMap();
private Color fColorInactive;
@@ -118,8 +118,7 @@ public class CHLabelProvider extends LabelProvider implements IColorProvider {
@Override
public void dispose() {
fCLabelProvider.dispose();
- for (Iterator iter = fCachedImages.values().iterator(); iter.hasNext();) {
- Image image = iter.next();
+ for (Image image : fCachedImages.values()) {
image.dispose();
}
fCachedImages.clear();
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHQueries.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHQueries.java
index 3c4850b0d3e..33976ada495 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHQueries.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHQueries.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
+ * Copyright (c) 2006, 2009 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
@@ -12,6 +12,8 @@ package org.eclipse.cdt.internal.ui.callhierarchy;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -20,15 +22,19 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexName;
+import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ISourceReference;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInstanceCache;
import org.eclipse.cdt.internal.core.model.ext.ICElementHandle;
import org.eclipse.cdt.internal.ui.viewsupport.IndexUI;
@@ -75,12 +81,12 @@ public class CHQueries {
final ICProject project = callee.getCProject();
IIndexBinding calleeBinding= IndexUI.elementToBinding(index, callee, linkageID);
if (calleeBinding != null) {
- findCalledBy(index, calleeBinding, true, project, result);
+ findCalledBy1(index, calleeBinding, true, project, result);
if (calleeBinding instanceof ICPPMethod) {
try {
IBinding[] overriddenBindings= ClassTypeHelper.findOverridden((ICPPMethod) calleeBinding);
for (IBinding overriddenBinding : overriddenBindings) {
- findCalledBy(index, overriddenBinding, false, project, result);
+ findCalledBy1(index, overriddenBinding, false, project, result);
}
} catch (DOMException e) {
// index bindings don't throw DOMExceptions
@@ -89,7 +95,57 @@ public class CHQueries {
}
}
- private static void findCalledBy(IIndex index, IBinding callee, boolean includeOrdinaryCalls, ICProject project, CalledByResult result)
+ private static void findCalledBy1(IIndex index, IBinding callee, boolean includeOrdinaryCalls,
+ ICProject project, CalledByResult result) throws CoreException {
+ findCalledBy2(index, callee, includeOrdinaryCalls, project, result);
+ List extends IBinding> specializations = findSpecializations(callee);
+ for (IBinding spec : specializations) {
+ findCalledBy2(index, spec, includeOrdinaryCalls, project, result);
+ }
+ }
+
+ private static List extends IBinding> findSpecializations(IBinding callee) throws CoreException {
+ try {
+ List result= null;
+
+ IBinding owner = callee.getOwner();
+ if (owner != null) {
+ List extends IBinding> specializedOwners= findSpecializations(owner);
+ if (!specializedOwners.isEmpty()) {
+ result= new ArrayList(specializedOwners.size());
+
+ for (IBinding specOwner : specializedOwners) {
+ if (specOwner instanceof ICPPClassSpecialization) {
+ result.add(((ICPPClassSpecialization) specOwner).specializeMember(callee));
+ }
+ }
+ }
+ }
+
+ if (callee instanceof ICPPInstanceCache) {
+ final List instances= Arrays.asList(((ICPPInstanceCache) callee).getAllInstances());
+ if (!instances.isEmpty()) {
+ if (result == null)
+ result= new ArrayList(instances.size());
+
+
+ for (ICPPTemplateInstance inst : instances) {
+ if (!IndexFilter.ALL_DECLARED.acceptBinding(inst)) {
+ result.add(inst);
+ }
+ }
+ }
+ }
+
+ if (result != null) {
+ return result;
+ }
+ } catch (DOMException e) {
+ }
+ return Collections.emptyList();
+ }
+
+ private static void findCalledBy2(IIndex index, IBinding callee, boolean includeOrdinaryCalls, ICProject project, CalledByResult result)
throws CoreException {
IIndexName[] names= index.findNames(callee, IIndex.FIND_REFERENCES | IIndex.SEARCH_ACROSS_LANGUAGE_BOUNDARIES);
for (IIndexName rname : names) {
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CallHierarchyUI.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CallHierarchyUI.java
index d9fc6d51b6c..a9eb3f86e9f 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CallHierarchyUI.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CallHierarchyUI.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
+ * Copyright (c) 2006, 2009 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,7 +8,6 @@
* Contributors:
* Markus Schorn - initial API and implementation
*******************************************************************************/
-
package org.eclipse.cdt.internal.ui.callhierarchy;
import org.eclipse.core.runtime.CoreException;
@@ -30,6 +29,7 @@ import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.c.ICExternalBinding;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.core.index.IIndexName;
@@ -164,39 +164,63 @@ public class CallHierarchyUI {
if (elem != null) {
return new ICElement[]{elem};
}
- }
- else {
- ICElement[] elems= IndexUI.findAllDefinitions(index, binding);
- if (elems.length == 0) {
- ICElement elem= null;
- if (name.isDeclaration()) {
- elem= IndexUI.getCElementForName(project, index, name);
- }
- else {
- elem= IndexUI.findAnyDeclaration(index, project, binding);
- }
- if (elem != null) {
- elems= new ICElement[]{elem};
- }
- }
+ return NO_ELEMENTS;
+ }
+
+ ICElement[] elems= IndexUI.findAllDefinitions(index, binding);
+ if (elems.length != 0)
return elems;
+
+ if (name.isDeclaration()) {
+ ICElementHandle elem= IndexUI.getCElementForName(project, index, name);
+ if (elem != null) {
+ return new ICElement[] {elem};
+ }
+ return NO_ELEMENTS;
}
+
+ ICElementHandle elem= IndexUI.findAnyDeclaration(index, project, binding);
+ if (elem != null) {
+ return new ICElement[]{elem};
+ }
+
+ if (binding instanceof ICPPSpecialization) {
+ return findSpecializationDeclaration(binding, project, index);
+ }
+ return NO_ELEMENTS;
}
}
}
finally {
index.releaseReadLock();
}
- }
- catch (CoreException e) {
+ } catch (CoreException e) {
CUIPlugin.log(e);
- }
- catch (InterruptedException e) {
+ } catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return NO_ELEMENTS;
}
+ private static ICElement[] findSpecializationDeclaration(IBinding binding, ICProject project,
+ IIndex index) throws CoreException {
+ while (binding instanceof ICPPSpecialization) {
+ IBinding original= ((ICPPSpecialization) binding).getSpecializedBinding();
+ ICElementHandle[] elems= IndexUI.findAllDefinitions(index, original);
+ if (elems.length == 0) {
+ ICElementHandle elem= IndexUI.findAnyDeclaration(index, project, original);
+ if (elem != null) {
+ elems= new ICElementHandle[]{elem};
+ }
+ }
+ if (elems.length > 0) {
+ return elems;
+ }
+ binding= original;
+ }
+ return NO_ELEMENTS;
+ }
+
public static ICElement[] findDefinitions(ICElement input) {
try {
final ITranslationUnit tu= CModelUtil.getTranslationUnit(input);