[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] Template Definitions
|
This patch:
-Adds template elements (classes, functions and methods) to core model.
-Updates the C Model Builder to recognize templates.
-Adds UI support for templates in outline view (The icon decorator goes to
\org.eclipse.cdt.ui\icons\full\ovr16).
Thanks,
Hoda
Attachment:
template_co.gif
Description: GIF image
Index: model/org/eclipse/cdt/core/model/ICElement.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICElement.java,v
retrieving revision 1.6
diff -u -r1.6 ICElement.java
--- model/org/eclipse/cdt/core/model/ICElement.java 31 Mar 2003 20:47:34 -0000 1.6
+++ model/org/eclipse/cdt/core/model/ICElement.java 10 Apr 2003 20:48:35 -0000
@@ -112,7 +112,7 @@
/**
* C++ template class.
*/
- static final int C_TEMPLATE = 73;
+ static final int C_TEMPLATE_CLASS = 73;
/**
* Global variable.
@@ -143,6 +143,16 @@
* Enumerator.
*/
static final int C_ENUMERATOR = 79;
+
+ /**
+ * C++ template function.
+ */
+ static final int C_TEMPLATE_FUNCTION = 80;
+
+ /**
+ * C++ template method.
+ */
+ static final int C_TEMPLATE_METHOD = 81;
/**
* Modifier indicating a class constructor
Index: model/org/eclipse/cdt/core/model/ITemplate.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITemplate.java,v
retrieving revision 1.1
diff -u -r1.1 ITemplate.java
--- model/org/eclipse/cdt/core/model/ITemplate.java 2 Feb 2003 01:01:57 -0000 1.1
+++ model/org/eclipse/cdt/core/model/ITemplate.java 10 Apr 2003 20:48:35 -0000
@@ -1,6 +1,33 @@
package org.eclipse.cdt.core.model;
-
-/**
- */
-public interface ITemplate extends IMember {
+/*******************************************************************************
+ * Copyright (c) 2001 Rational Software Corp. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * Rational Software - initial implementation
+ ******************************************************************************/
+public interface ITemplate extends IDeclaration {
+ /**
+ * Returns the template parameter types.
+ * @return String
+ */
+ String[] getTemplateParameterTypes();
+ /**
+ * Sets the template parameter types.
+ * @param paramTypes
+ */
+ void setTemplateParameterTypes(String[] templateParameterTypes);
+ /**
+ * Returns the template signature
+ * @return String
+ */
+ String getTemplateSignature();
+ /**
+ * Returns the number of template parameters
+ * @return int
+ */
+ int getNumberOfTemplateParameters();
}
Index: model/org/eclipse/cdt/internal/core/model/ClassTemplate.java
===================================================================
RCS file: model/org/eclipse/cdt/internal/core/model/ClassTemplate.java
diff -N model/org/eclipse/cdt/internal/core/model/ClassTemplate.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ model/org/eclipse/cdt/internal/core/model/ClassTemplate.java 10 Apr 2003 20:48:37 -0000
@@ -0,0 +1,71 @@
+package org.eclipse.cdt.internal.core.model;
+
+/**********************************************************************
+ * Copyright (c) 2002,2003 Rational Software Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * Rational Software - Initial API and implementation
+***********************************************************************/
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ITemplate;
+
+public class ClassTemplate extends Structure implements ITemplate{
+
+ protected static final String[] fgEmptyList= new String[] {};
+ protected String[] templateParameterTypes;
+
+ public ClassTemplate(ICElement parent, String name) {
+ super(parent, CElement.C_TEMPLATE_CLASS, name);
+ templateParameterTypes= fgEmptyList;
+ }
+ /**
+ * Returns the parameterTypes.
+ * @see org.eclipse.cdt.core.model.ITemplate#getParameters()
+ * @return String[]
+ */
+ public String[] getTemplateParameterTypes() {
+ return templateParameterTypes;
+ }
+
+ /**
+ * Sets the fParameterTypes.
+ * @param fParameterTypes The fParameterTypes to set
+ */
+ public void setTemplateParameterTypes(String[] templateParameterTypes) {
+ this.templateParameterTypes = templateParameterTypes;
+ }
+
+ /**
+ * @see org.eclipse.cdt.core.model.ITemplate#getNumberOfTemplateParameters()
+ */
+ public int getNumberOfTemplateParameters() {
+ return templateParameterTypes == null ? 0 : templateParameterTypes.length;
+ }
+
+ /**
+ * @see org.eclipse.cdt.core.model.ITemplate#getTemplateSignature()
+ */
+ public String getTemplateSignature() {
+ StringBuffer sig = new StringBuffer(getElementName());
+ if(getNumberOfTemplateParameters() > 0){
+ sig.append("<");
+ String[] paramTypes = getTemplateParameterTypes();
+ int i = 0;
+ sig.append(paramTypes[i++]);
+ while (i < paramTypes.length){
+ sig.append(", ");
+ sig.append(paramTypes[i++]);
+ }
+ sig.append(">");
+ }
+ else{
+ sig.append("<>");
+ }
+ return sig.toString();
+ }
+
+}
Index: model/org/eclipse/cdt/internal/core/model/FunctionTemplate.java
===================================================================
RCS file: model/org/eclipse/cdt/internal/core/model/FunctionTemplate.java
diff -N model/org/eclipse/cdt/internal/core/model/FunctionTemplate.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ model/org/eclipse/cdt/internal/core/model/FunctionTemplate.java 10 Apr 2003 20:48:36 -0000
@@ -0,0 +1,78 @@
+package org.eclipse.cdt.internal.core.model;
+
+/**********************************************************************
+ * Copyright (c) 2002,2003 Rational Software Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * Rational Software - Initial API and implementation
+***********************************************************************/
+
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ITemplate;
+
+public class FunctionTemplate extends FunctionDeclaration implements ITemplate{
+
+ protected static final String[] fgEmptyList= new String[] {};
+ protected String[] templateParameterTypes;
+
+ public FunctionTemplate(ICElement parent, String name) {
+ super(parent, name, CElement.C_TEMPLATE_FUNCTION);
+ templateParameterTypes= fgEmptyList;
+ }
+
+ /**
+ * Returns the parameterTypes.
+ * @see org.eclipse.cdt.core.model.ITemplate#getParameters()
+ * @return String[]
+ */
+ public String[] getTemplateParameterTypes() {
+ return templateParameterTypes;
+ }
+
+ /**
+ * Sets the fParameterTypes.
+ * @param fParameterTypes The fParameterTypes to set
+ */
+ public void setTemplateParameterTypes(String[] templateParameterTypes) {
+ this.templateParameterTypes = templateParameterTypes;
+ }
+ /**
+ * @see org.eclipse.cdt.core.model.ITemplate#getNumberOfTemplateParameters()
+ */
+ public int getNumberOfTemplateParameters() {
+ return templateParameterTypes == null ? 0 : templateParameterTypes.length;
+ }
+
+ /**
+ * @see org.eclipse.cdt.core.model.ITemplate#getTemplateSignature()
+ */
+ public String getTemplateSignature() {
+ StringBuffer sig = new StringBuffer(getElementName());
+ if(getNumberOfTemplateParameters() > 0){
+ sig.append("<");
+ String[] paramTypes = getTemplateParameterTypes();
+ int i = 0;
+ sig.append(paramTypes[i++]);
+ while (i < paramTypes.length){
+ sig.append(", ");
+ sig.append(paramTypes[i++]);
+ }
+ sig.append(">");
+ }
+ else{
+ sig.append("<>");
+ }
+ sig.append(this.getSignature());
+ if((this.getReturnType() != null) && (this.getReturnType().length() > 0)){
+ sig.append(" : ");
+ sig.append(this.getReturnType());
+ }
+
+ return sig.toString();
+ }
+
+}
Index: model/org/eclipse/cdt/internal/core/model/MethodTemplate.java
===================================================================
RCS file: model/org/eclipse/cdt/internal/core/model/MethodTemplate.java
diff -N model/org/eclipse/cdt/internal/core/model/MethodTemplate.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ model/org/eclipse/cdt/internal/core/model/MethodTemplate.java 10 Apr 2003 20:48:37 -0000
@@ -0,0 +1,79 @@
+package org.eclipse.cdt.internal.core.model;
+
+/**********************************************************************
+ * Copyright (c) 2002,2003 Rational Software Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * Rational Software - Initial API and implementation
+***********************************************************************/
+
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ITemplate;
+
+public class MethodTemplate extends MethodDeclaration implements ITemplate{
+
+ protected static final String[] fgEmptyList= new String[] {};
+ protected String[] templateParameterTypes;
+
+ public MethodTemplate(ICElement parent, String name) {
+ super(parent, name, CElement.C_TEMPLATE_METHOD);
+ templateParameterTypes= fgEmptyList;
+ }
+
+ /**
+ * Returns the parameterTypes.
+ * @see org.eclipse.cdt.core.model.ITemplate#getParameters()
+ * @return String[]
+ */
+ public String[] getTemplateParameterTypes() {
+ return templateParameterTypes;
+ }
+
+ /**
+ * Sets the fParameterTypes.
+ * @param fParameterTypes The fParameterTypes to set
+ */
+ public void setTemplateParameterTypes(String[] templateParameterTypes) {
+ this.templateParameterTypes = templateParameterTypes;
+ }
+ /**
+ * @see org.eclipse.cdt.core.model.ITemplate#getNumberOfTemplateParameters()
+ */
+ public int getNumberOfTemplateParameters() {
+ return templateParameterTypes == null ? 0 : templateParameterTypes.length;
+ }
+
+ /**
+ * @see org.eclipse.cdt.core.model.ITemplate#getTemplateSignature()
+ */
+ public String getTemplateSignature() {
+ StringBuffer sig = new StringBuffer(getElementName());
+ if(getNumberOfTemplateParameters() > 0){
+ sig.append("<");
+ String[] paramTypes = getTemplateParameterTypes();
+ int i = 0;
+ sig.append(paramTypes[i++]);
+ while (i < paramTypes.length){
+ sig.append(", ");
+ sig.append(paramTypes[i++]);
+ }
+ sig.append(">");
+ }
+ else{
+ sig.append("<>");
+ }
+ sig.append(this.getSignature());
+ if((this.getReturnType() != null) && (this.getReturnType().length() > 0)){
+ sig.append(" : ");
+ sig.append(this.getReturnType());
+ }
+
+ return sig.toString();
+ }
+
+}
+
Index: model/org/eclipse/cdt/internal/core/model/Template.java
===================================================================
RCS file: model/org/eclipse/cdt/internal/core/model/Template.java
diff -N model/org/eclipse/cdt/internal/core/model/Template.java
--- model/org/eclipse/cdt/internal/core/model/Template.java 31 Mar 2003 16:33:54 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,62 +0,0 @@
-package org.eclipse.cdt.internal.core.model;
-
-/**********************************************************************
- * Copyright (c) 2002,2003 Rational Software Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v0.5
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v05.html
- *
- * Contributors:
- * Rational Software - Initial API and implementation
-***********************************************************************/
-
-import org.eclipse.cdt.core.model.ICElement;
-import org.eclipse.cdt.core.model.ITemplate;
-
-public class Template extends SourceManipulation implements ITemplate{
-
- public Template(ICElement parent, String name) {
- super(parent, name, CElement.C_TEMPLATE);
- }
-
- protected CElementInfo createElementInfo () {
- return new SourceManipulationInfo(this);
- }
-
- /**
- * @see org.eclipse.cdt.core.model.IMember#getVisibility()
- */
- public int getVisibility() {
- return 0;
- }
-
- /**
- * @see org.eclipse.cdt.core.model.IDeclaration#getAccessControl()
- */
- public int getAccessControl() {
- return 0;
- }
-
- /**
- * @see org.eclipse.cdt.core.model.IDeclaration#isConst()
- */
- public boolean isConst() {
- return false;
- }
-
- /**
- * @see org.eclipse.cdt.core.model.IDeclaration#isStatic()
- */
- public boolean isStatic() {
- return false;
- }
-
- /**
- * @see org.eclipse.cdt.core.model.IDeclaration#isVolatile()
- */
- public boolean isVolatile() {
- return false;
- }
-
-}
Index: parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java,v
retrieving revision 1.4
diff -u -r1.4 CModelBuilder.java
--- parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java 9 Apr 2003 21:11:59 -0000 1.4
+++ parser/org/eclipse/cdt/internal/core/model/CModelBuilder.java 10 Apr 2003 20:48:41 -0000
@@ -19,6 +19,7 @@
import org.eclipse.cdt.core.model.INamespace;
import org.eclipse.cdt.core.model.IParent;
import org.eclipse.cdt.core.model.IStructure;
+import org.eclipse.cdt.core.model.ITemplate;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.core.dom.ClassKey;
import org.eclipse.cdt.internal.core.dom.ClassSpecifier;
@@ -30,6 +31,7 @@
import org.eclipse.cdt.internal.core.dom.EnumerationSpecifier;
import org.eclipse.cdt.internal.core.dom.EnumeratorDefinition;
import org.eclipse.cdt.internal.core.dom.IOffsetable;
+import org.eclipse.cdt.internal.core.dom.ITemplateParameterListOwner;
import org.eclipse.cdt.internal.core.dom.Inclusion;
import org.eclipse.cdt.internal.core.dom.Macro;
import org.eclipse.cdt.internal.core.dom.NamespaceDefinition;
@@ -37,6 +39,8 @@
import org.eclipse.cdt.internal.core.dom.ParameterDeclarationClause;
import org.eclipse.cdt.internal.core.dom.PointerOperator;
import org.eclipse.cdt.internal.core.dom.SimpleDeclaration;
+import org.eclipse.cdt.internal.core.dom.TemplateDeclaration;
+import org.eclipse.cdt.internal.core.dom.TemplateParameter;
import org.eclipse.cdt.internal.core.dom.TranslationUnit;
import org.eclipse.cdt.internal.core.dom.TypeSpecifier;
import org.eclipse.cdt.internal.core.parser.Parser;
@@ -77,7 +81,7 @@
}
protected void generateModelElements (Parent parent, Declaration declaration){
- // Namespace
+ // Namespace Definition
if(declaration instanceof NamespaceDefinition){
NamespaceDefinition nsDef = (NamespaceDefinition) declaration;
IParent namespace = createNamespace(parent, nsDef);
@@ -87,8 +91,9 @@
Declaration subNsDeclaration = (Declaration) nsDecls.next();
generateModelElements((Parent)namespace, subNsDeclaration);
}
- }
+ }// end Namespace Definition
+ // Simple Declaration
if(declaration instanceof SimpleDeclaration){
SimpleDeclaration simpleDeclaration = (SimpleDeclaration) declaration;
@@ -104,43 +109,93 @@
// Structure
else if (typeSpec instanceof ClassSpecifier){
ClassSpecifier classSpecifier = (ClassSpecifier) typeSpec;
- IParent classElement = createClass (parent, simpleDeclaration, classSpecifier);
+ IParent classElement = createClass (parent, simpleDeclaration, classSpecifier, false);
// create the sub declarations
List declarations = classSpecifier.getDeclarations();
Iterator j = declarations.iterator();
while (j.hasNext()){
Declaration subDeclaration = (Declaration)j.next();
generateModelElements((Parent)classElement, subDeclaration);
- }
- // TODO: create the declarators too here
+ } // end while j
}
-
/*-----------------------------------------
* Create declarators of simple declaration
* ----------------------------------------*/
+ List declarators = simpleDeclaration.getDeclarators();
+ Iterator d = declarators.iterator();
+ while (d.hasNext()){
+ Declarator declarator = (Declarator)d.next();
+ createElement(parent, simpleDeclaration, declarator);
+ } // end while d
+ } // end if SimpleDeclaration
+
+ // Template Declaration
+ if(declaration instanceof TemplateDeclaration){
+ TemplateDeclaration templateDeclaration = (TemplateDeclaration)declaration;
+ SimpleDeclaration simpleDeclaration = (SimpleDeclaration)templateDeclaration.getDeclarations().get(0);
+ TypeSpecifier typeSpec = simpleDeclaration.getTypeSpecifier();
+ if (typeSpec instanceof ClassSpecifier){
+ ClassSpecifier classSpecifier = (ClassSpecifier) typeSpec;
+ ITemplate classTemplate = (ClassTemplate)createClass(parent, simpleDeclaration, classSpecifier, true);
+ String[] parameterTypes = getTemplateParameters(templateDeclaration);
+ classTemplate.setTemplateParameterTypes(parameterTypes);
+ // create the sub declarations
+ List declarations = classSpecifier.getDeclarations();
+ Iterator j = declarations.iterator();
+ while (j.hasNext()){
+ Declaration subDeclaration = (Declaration)j.next();
+ generateModelElements((Parent)classTemplate, subDeclaration);
+ } // end while j
+ }
List declarators = simpleDeclaration.getDeclarators();
Iterator d = declarators.iterator();
while (d.hasNext()){
Declarator declarator = (Declarator)d.next();
- // typedef
- if(simpleDeclaration.getDeclSpecifier().isTypedef()){
- createTypeDef(parent, declarator, simpleDeclaration);
- } else {
- ParameterDeclarationClause pdc = declarator.getParms();
- if (pdc == null){
- createVariableSpecification(parent, simpleDeclaration, declarator);
- }
- else{
- createFunctionSpecification(parent, simpleDeclaration, declarator, pdc);
- }
- }
- } // end while
- } // end if SimpleDeclaration
+ createTemplateElement(parent,templateDeclaration, simpleDeclaration, declarator);
+ } // end while d
+
+ }// end Template Declaration
+
+ }
+
+ private void createElement(Parent parent, SimpleDeclaration simpleDeclaration, Declarator declarator){
+ // typedef
+ if(simpleDeclaration.getDeclSpecifier().isTypedef()){
+ createTypeDef(parent, declarator, simpleDeclaration);
+ } else {
+ ParameterDeclarationClause pdc = declarator.getParms();
+ if (pdc == null){
+ createVariableSpecification(parent, simpleDeclaration, declarator);
+ }
+ else{
+ createFunctionSpecification(parent, simpleDeclaration, declarator, pdc, false);
+ }
+ }
+ }
+
+ private void createTemplateElement(Parent parent, TemplateDeclaration templateDeclaration, SimpleDeclaration simpleDeclaration, Declarator declarator){
+ ParameterDeclarationClause pdc = declarator.getParms();
+ if (pdc != null){
+ ITemplate template = (ITemplate) createFunctionSpecification(parent, simpleDeclaration, declarator, pdc, true);
+ String[] parameterTypes = getTemplateParameters(templateDeclaration);
+ template.setTemplateParameterTypes(parameterTypes);
+
+ }
+/*// typedef
+ if(simpleDeclaration.getDeclSpecifier().isTypedef()){
+ createTypeDef(parent, declarator, simpleDeclaration);
+ } else {
+ ParameterDeclarationClause pdc = declarator.getParms();
+ if (pdc == null){
+ createVariableSpecification(parent, simpleDeclaration, declarator);
+ }
+ else{
+ createFunctionSpecification(parent, simpleDeclaration, declarator, pdc);
+ }
+ }
+*/
}
-
-
-
private void createInclusion(Parent parent, Inclusion inclusion){
// create element
Include element = new Include((CElement)parent, inclusion.getName());
@@ -211,7 +266,7 @@
return (IParent)enum;
}
- private IParent createClass(Parent parent, SimpleDeclaration simpleDeclaration, ClassSpecifier classSpecifier){
+ private IParent createClass(Parent parent, SimpleDeclaration simpleDeclaration, ClassSpecifier classSpecifier, boolean isTemplate){
// create element
String className = (classSpecifier.getName() == null ) ? "" : classSpecifier.getName().toString();
int kind;
@@ -228,27 +283,35 @@
break;
}
- Structure classElement = new Structure( (CElement)parent, kind, className );
+ Structure element;
+ if(!isTemplate){
+ Structure classElement = new Structure( (CElement)parent, kind, className );
+ element = classElement;
+ } else {
+ ClassTemplate classTemplate = new ClassTemplate( (CElement)parent, className );
+ element = classTemplate;
+ }
+
// add to parent
- parent.addChild((ICElement) classElement);
+ parent.addChild((ICElement) element);
String type;
// set element position
if( classSpecifier.getName() != null )
{
type = simpleDeclaration.getDeclSpecifier().getTypeName();
- classElement.setIdPos( classSpecifier.getName().getStartOffset(), classSpecifier.getName().length() );
+ element.setIdPos( classSpecifier.getName().getStartOffset(), classSpecifier.getName().length() );
}
else
{
type = classSpecifier.getClassKeyToken().getImage();
- classElement.setIdPos(classSpecifier.getClassKeyToken().getOffset(), classSpecifier.getClassKeyToken().getLength());
+ element.setIdPos(classSpecifier.getClassKeyToken().getOffset(), classSpecifier.getClassKeyToken().getLength());
}
- classElement.setTypeName( type );
- classElement.setPos(classSpecifier.getStartingOffset(), classSpecifier.getTotalLength());
+ element.setTypeName( type );
+ element.setPos(classSpecifier.getStartingOffset(), classSpecifier.getTotalLength());
- return classElement;
+ return element;
}
private void createTypeDef(Parent parent, Declarator declarator, SimpleDeclaration simpleDeclaration){
@@ -266,7 +329,7 @@
typedef.setPos(simpleDeclaration.getStartingOffset(), simpleDeclaration.getTotalLength());
}
- private void createVariableSpecification(Parent parent, SimpleDeclaration simpleDeclaration, Declarator declarator){
+ private VariableDeclaration createVariableSpecification(Parent parent, SimpleDeclaration simpleDeclaration, Declarator declarator){
String declaratorName = declarator.getName().toString();
DeclSpecifier declSpecifier = simpleDeclaration.getDeclSpecifier();
@@ -299,13 +362,13 @@
parent.addChild( element );
// set position
- // hook up the offsets
element.setIdPos( declarator.getName().getStartOffset(), declarator.getName().length() );
- element.setPos(simpleDeclaration.getStartingOffset(), simpleDeclaration.getTotalLength());
-
+ element.setPos(simpleDeclaration.getStartingOffset(), simpleDeclaration.getTotalLength());
+
+ return element;
}
- private void createFunctionSpecification(Parent parent, SimpleDeclaration simpleDeclaration, Declarator declarator, ParameterDeclarationClause pdc){
+ private FunctionDeclaration createFunctionSpecification(Parent parent, SimpleDeclaration simpleDeclaration, Declarator declarator, ParameterDeclarationClause pdc, boolean isTemplate){
String declaratorName = declarator.getName().toString();
DeclSpecifier declSpecifier = simpleDeclaration.getDeclSpecifier();
// getParameterTypes
@@ -315,8 +378,7 @@
for( int j = 0; j< parameterList.size(); ++j )
{
ParameterDeclaration param = (ParameterDeclaration )parameterList.get(j);
- Declarator paramDeclarator = (Declarator)param.getDeclarators().get(0);
- parameterTypes[j] = new String(getType(param, paramDeclarator));
+ parameterTypes[j] = new String(getType(param, (Declarator)param.getDeclarators().get(0)));
}
if( parent instanceof IStructure )
@@ -331,9 +393,16 @@
else
{
// method declaration
- MethodDeclaration newElement = new MethodDeclaration( parent, declaratorName );
- newElement.setVisibility(simpleDeclaration.getAccessSpecifier().getAccess());
- element = newElement;
+ if(!isTemplate){
+ MethodDeclaration newElement = new MethodDeclaration( parent, declaratorName );
+ newElement.setVisibility(simpleDeclaration.getAccessSpecifier().getAccess());
+ element = newElement;
+ }else {
+ MethodTemplate newElement = new MethodTemplate(parent, declaratorName);
+ // newElement.setVisibility(simpleDeclaration.getAccessSpecifier().getAccess());
+ element = newElement;
+ }
+
}
}
else if(( parent instanceof ITranslationUnit )
@@ -352,8 +421,13 @@
else
{
// functionDeclaration
- FunctionDeclaration newElement = new FunctionDeclaration( parent, declaratorName );
- element = newElement;
+ if(!isTemplate){
+ FunctionDeclaration newElement = new FunctionDeclaration( parent, declaratorName );
+ element = newElement;
+ } else {
+ FunctionTemplate newElement = new FunctionTemplate( parent, declaratorName );
+ element = newElement;
+ }
}
}
element.setParameterTypes(parameterTypes);
@@ -368,7 +442,55 @@
// hook up the offsets
element.setIdPos( declarator.getName().getStartOffset(), declarator.getName().length() );
element.setPos(simpleDeclaration.getStartingOffset(), simpleDeclaration.getTotalLength());
+ return element;
+ }
+
+ private String[] getTemplateParameters(ITemplateParameterListOwner templateDeclaration){
+ // add the parameters
+ List templateParameters = templateDeclaration.getTemplateParms().getDeclarations();
+ Iterator i = templateParameters.iterator();
+ String[] parameterTypes = new String[templateParameters.size()];
+ for( int j = 0; j< templateParameters.size(); ++j ){
+ StringBuffer paramType = new StringBuffer();
+ Declaration decl = (Declaration)templateParameters.get(j);
+ if(decl instanceof TemplateParameter){
+ TemplateParameter parameter = (TemplateParameter) decl;
+ if(parameter.getName() != null){
+ paramType.append(" ");
+ paramType.append(parameter.getName().toString());
+ }else {
+ int kind = parameter.getKind();
+ switch (kind){
+ case TemplateParameter.k_class:
+ paramType.append("class");
+ break;
+ case TemplateParameter.k_typename:
+ paramType.append("typename");
+ break;
+ case TemplateParameter.k_template:
+ paramType.append("template<");
+ String[] subParams =getTemplateParameters(parameter);
+ int p = 0;
+ if ( subParams.length > 0)
+ paramType.append(subParams[p++]);
+ while( p < subParams.length){
+ paramType.append(", ");
+ paramType.append(subParams[p++]);
+ }
+ paramType.append(">");
+ break;
+ default:
+ break;
+ } // switch
+ }
+ } else if(decl instanceof ParameterDeclaration){
+ ParameterDeclaration parameter = (ParameterDeclaration) decl;
+ paramType.append(getType(parameter, (Declarator)parameter.getDeclarators().get(0)));
+ }
+ parameterTypes[j] = new String(paramType.toString());
+ } // end for
+ return parameterTypes;
}
private String getType(Declaration declaration, Declarator declarator){
Index: icons/full/ovr16/template_co.gif
===================================================================
RCS file: icons/full/ovr16/template_co.gif
diff -N icons/full/ovr16/template_co.gif
Binary files /dev/null and template_co.gif differ
Index: src/org/eclipse/cdt/internal/ui/CElementImageProvider.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CElementImageProvider.java,v
retrieving revision 1.13
diff -u -r1.13 CElementImageProvider.java
--- src/org/eclipse/cdt/internal/ui/CElementImageProvider.java 4 Apr 2003 20:38:20 -0000 1.13
+++ src/org/eclipse/cdt/internal/ui/CElementImageProvider.java 10 Apr 2003 20:51:37 -0000
@@ -10,10 +10,11 @@
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IDeclaration;
+import org.eclipse.cdt.core.model.IField;
import org.eclipse.cdt.core.model.ILibraryReference;
import org.eclipse.cdt.core.model.IMember;
import org.eclipse.cdt.core.model.IMethodDeclaration;
-import org.eclipse.cdt.core.model.IField;
+import org.eclipse.cdt.core.model.ITemplate;
import org.eclipse.cdt.internal.ui.util.ImageDescriptorRegistry;
import org.eclipse.cdt.ui.CElementImageDescriptor;
import org.eclipse.cdt.ui.CUIPlugin;
@@ -206,6 +207,7 @@
return CPluginImages.DESC_OBJS_STRUCT;
case ICElement.C_CLASS:
+ case ICElement.C_TEMPLATE_CLASS:
return CPluginImages.DESC_OBJS_CLASS;
case ICElement.C_UNION:
@@ -236,6 +238,7 @@
case ICElement.C_METHOD:
case ICElement.C_METHOD_DECLARATION:
+ case ICElement.C_TEMPLATE_METHOD:
IMethodDeclaration md= (IMethodDeclaration)celement;
switch(md.getVisibility()){
case IMember.V_PUBLIC:
@@ -245,6 +248,7 @@
case IMember.V_PRIVATE:
return CPluginImages.DESC_OBJS_PRIVATE_METHOD;
}
+
case ICElement.C_FUNCTION:
return CPluginImages.DESC_OBJS_FUNCTION;
@@ -252,6 +256,7 @@
return CPluginImages.DESC_OBJS_VAR_DECLARARION;
case ICElement.C_FUNCTION_DECLARATION:
+ case ICElement.C_TEMPLATE_FUNCTION:
return CPluginImages.DESC_OBJS_DECLARARION;
case ICElement.C_INCLUDE:
@@ -262,7 +267,7 @@
case ICElement.C_NAMESPACE:
return CPluginImages.DESC_OBJS_CONTAINER;
-
+
}
return null;
}
@@ -284,6 +289,9 @@
}
if(decl.isVolatile()){
flags |= CElementImageDescriptor.VOLATILE;
+ }
+ if(element instanceof ITemplate){
+ flags |= CElementImageDescriptor.TEMPLATE;
}
}
return flags;
Index: src/org/eclipse/cdt/internal/ui/CPluginImages.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java,v
retrieving revision 1.13
diff -u -r1.13 CPluginImages.java
--- src/org/eclipse/cdt/internal/ui/CPluginImages.java 10 Apr 2003 19:25:56 -0000 1.13
+++ src/org/eclipse/cdt/internal/ui/CPluginImages.java 10 Apr 2003 20:51:36 -0000
@@ -126,6 +126,7 @@
public static final ImageDescriptor DESC_OVR_STATIC= create(T_OVR, "static_co.gif");
public static final ImageDescriptor DESC_OVR_CONSTANT= create(T_OVR, "c_ovr.gif");
public static final ImageDescriptor DESC_OVR_VOLATILE= create(T_OVR, "volatile_co.gif");
+ public static final ImageDescriptor DESC_OVR_TEMPLATE= create(T_OVR, "template_co.gif");
public static final ImageDescriptor DESC_OVR_WARNING= create(T_OVR, "warning_co.gif");
public static final ImageDescriptor DESC_OVR_ERROR= create(T_OVR, "error_co.gif");
Index: src/org/eclipse/cdt/ui/CElementImageDescriptor.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementImageDescriptor.java,v
retrieving revision 1.4
diff -u -r1.4 CElementImageDescriptor.java
--- src/org/eclipse/cdt/ui/CElementImageDescriptor.java 9 Apr 2003 15:07:59 -0000 1.4
+++ src/org/eclipse/cdt/ui/CElementImageDescriptor.java 10 Apr 2003 20:51:35 -0000
@@ -31,7 +31,7 @@
public class CElementImageDescriptor extends CompositeImageDescriptor {
/** Flag to render the abstract adornment */
- public final static int ABSTRACT= 0x001;
+ public final static int TEMPLATE= 0x001;
/** Flag to render the const adornment */
public final static int CONSTANT= 0x002;
@@ -177,6 +177,11 @@
x-= data.width;
drawImage(data, x, 0);
}
+ if ((fFlags & TEMPLATE) != 0) {
+ data= CPluginImages.DESC_OVR_TEMPLATE.getImageData();
+ x-= data.width;
+ drawImage(data, x, 0);
+ }
}
private void drawBottomRight() {
Index: src/org/eclipse/cdt/ui/CElementLabelProvider.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementLabelProvider.java,v
retrieving revision 1.12
diff -u -r1.12 CElementLabelProvider.java
--- src/org/eclipse/cdt/ui/CElementLabelProvider.java 9 Apr 2003 15:07:59 -0000 1.12
+++ src/org/eclipse/cdt/ui/CElementLabelProvider.java 10 Apr 2003 20:51:35 -0000
@@ -9,6 +9,7 @@
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IFunctionDeclaration;
import org.eclipse.cdt.core.model.INamespace;
+import org.eclipse.cdt.core.model.ITemplate;
import org.eclipse.cdt.core.model.ITypeDef;
import org.eclipse.cdt.core.model.IVariableDeclaration;
import org.eclipse.cdt.internal.ui.CElementImageProvider;
@@ -108,6 +109,13 @@
INamespace nDecl = (INamespace) celem;
name.append(nDecl.getTypeName());
}
+ break;
+ case ICElement.C_TEMPLATE_CLASS:
+ case ICElement.C_TEMPLATE_FUNCTION:
+ case ICElement.C_TEMPLATE_METHOD:
+ ITemplate template = (ITemplate) celem;
+ String signature = template.getTemplateSignature();
+ name.append(signature);
break;
default:
name.append(celem.getElementName());