mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Proper template support in call hierarchy, bug 240589.
This commit is contained in:
parent
0d66821cc1
commit
7c27796dbd
19 changed files with 484 additions and 105 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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. <code>MyClass : public BaseClass</code>
|
||||
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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[])
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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<int>::Foo(const int &)").getParent();
|
||||
TreeItem item= checkTreeNode(chTree, 0, 0, "test()");
|
||||
checkTreeNode(chTree, 0, 1, null);
|
||||
}
|
||||
|
|
|
@ -375,4 +375,94 @@ public class CppCallHierarchyTest extends CallHierarchyBaseTest {
|
|||
checkTreeNode(node, 0, "cfunc()");
|
||||
checkTreeNode(node, 1, null);
|
||||
}
|
||||
|
||||
// template<typename T> void f(T t) {}
|
||||
// template<> void f(int t) {}
|
||||
//
|
||||
// template<typename T> class CT {
|
||||
// public:
|
||||
// void m() {};
|
||||
// };
|
||||
// template<typename T> class CT<T*> {
|
||||
// public:
|
||||
// void m() {};
|
||||
// };
|
||||
// template<> class CT<char> {
|
||||
// public:
|
||||
// void m() {}
|
||||
// };
|
||||
//
|
||||
// void testint() {
|
||||
// CT<int> ci;
|
||||
// ci.m();
|
||||
// f(1);
|
||||
// }
|
||||
//
|
||||
// void testintptr() {
|
||||
// CT<int*> ci;
|
||||
// ci.m();
|
||||
// int i= 1;
|
||||
// f(&i);
|
||||
// }
|
||||
//
|
||||
// void testchar() {
|
||||
// CT<char> 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>(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>(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<T>::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<T*>::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<char>::m()");
|
||||
checkTreeNode(tree, 0, 0, "testchar()");
|
||||
checkTreeNode(tree, 0, 1, null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String, Image> fCachedImages= new HashMap<String, Image>();
|
||||
private Color fColorInactive;
|
||||
|
@ -118,8 +118,7 @@ public class CHLabelProvider extends LabelProvider implements IColorProvider {
|
|||
@Override
|
||||
public void dispose() {
|
||||
fCLabelProvider.dispose();
|
||||
for (Iterator<Image> iter = fCachedImages.values().iterator(); iter.hasNext();) {
|
||||
Image image = iter.next();
|
||||
for (Image image : fCachedImages.values()) {
|
||||
image.dispose();
|
||||
}
|
||||
fCachedImages.clear();
|
||||
|
|
|
@ -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<IBinding> result= null;
|
||||
|
||||
IBinding owner = callee.getOwner();
|
||||
if (owner != null) {
|
||||
List<? extends IBinding> specializedOwners= findSpecializations(owner);
|
||||
if (!specializedOwners.isEmpty()) {
|
||||
result= new ArrayList<IBinding>(specializedOwners.size());
|
||||
|
||||
for (IBinding specOwner : specializedOwners) {
|
||||
if (specOwner instanceof ICPPClassSpecialization) {
|
||||
result.add(((ICPPClassSpecialization) specOwner).specializeMember(callee));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (callee instanceof ICPPInstanceCache) {
|
||||
final List<ICPPTemplateInstance> instances= Arrays.asList(((ICPPInstanceCache) callee).getAllInstances());
|
||||
if (!instances.isEmpty()) {
|
||||
if (result == null)
|
||||
result= new ArrayList<IBinding>(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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue