From c13b3fc24062da73702c3b47fbbf893cc1886904 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Mon, 31 Mar 2003 20:47:34 +0000 Subject: [PATCH] Patch for Hoda Amer: This patch adds a new C Model Element Type: Enumerator. It also displays the element's type name instead of the element's name if the element's name is null. --- .../org/eclipse/cdt/core/model/ICElement.java | 5 +++ .../eclipse/cdt/core/model/IEnumerator.java | 21 +++++++++ .../org/eclipse/cdt/core/model/IParent.java | 14 ++++-- .../cdt/internal/core/model/Enumeration.java | 38 ++++++++++++++-- .../cdt/internal/core/model/Enumerator.java | 43 +++++++++++++++++++ .../eclipse/cdt/ui/CElementLabelProvider.java | 10 ++++- 6 files changed, 123 insertions(+), 8 deletions(-) create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IEnumerator.java create mode 100644 core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Enumerator.java diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICElement.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICElement.java index 45affa0f216..5b4265eb395 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICElement.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ICElement.java @@ -139,6 +139,11 @@ public interface ICElement extends IAdaptable { */ static final int C_TYPEDEF = 78; + /** + * Enumerator. + */ + static final int C_ENUMERATOR = 79; + /** * Modifier indicating a class constructor */ diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IEnumerator.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IEnumerator.java new file mode 100644 index 00000000000..c9075c250b9 --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IEnumerator.java @@ -0,0 +1,21 @@ +package org.eclipse.cdt.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 +***********************************************************************/ +public interface IEnumerator extends ISourceManipulation{ + + /** + * Returns the enumerator constant expression if any. + * Returns null otherwise. + * @return String + */ + String getConstantExpression(); +} diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IParent.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IParent.java index a31077e022f..c375b4e7f2e 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IParent.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/IParent.java @@ -1,5 +1,7 @@ package org.eclipse.cdt.core.model; +import java.util.ArrayList; + /* * (c) Copyright QNX Software Systems Ltd. 2002. * All Rights Reserved. @@ -17,8 +19,12 @@ public interface IParent { * @exception CModelException if this element does not exist or if an * exception occurs while accessing its corresponding resource */ - ICElement[] getChildren(); //throws CModelException; - + ICElement[] getChildren(); + + /** + * returns the children of a certain type + */ + public ArrayList getChildrenOfType(int type); /** * Returns whether this element has one or more immediate children. * This is a convenience method, and may be more efficient than @@ -27,5 +33,7 @@ public interface IParent { * @exception CModelException if this element does not exist or if an * exception occurs while accessing its corresponding resource */ - boolean hasChildren(); //throws CModelException; + boolean hasChildren(); + + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Enumeration.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Enumeration.java index 0767d893ab8..5c8736f6174 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Enumeration.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Enumeration.java @@ -16,6 +16,11 @@ import org.eclipse.cdt.core.model.IEnumeration; public class Enumeration extends SourceManipulation implements IEnumeration{ + String typeName = ""; + boolean isStatic = false; + boolean isConst = false; + boolean isVolatile = false; + public Enumeration(ICElement parent, String name) { super(parent, name, CElement.C_ENUMERATION); } @@ -35,13 +40,14 @@ public class Enumeration extends SourceManipulation implements IEnumeration{ * @see org.eclipse.cdt.core.model.IVariableDeclaration#getTypeName() */ public String getTypeName() { - return null; + return typeName; } /** * @see org.eclipse.cdt.core.model.IVariableDeclaration#setTypeName(java.lang.String) */ public void setTypeName(String type) { + typeName = type; } /** @@ -55,21 +61,45 @@ public class Enumeration extends SourceManipulation implements IEnumeration{ * @see org.eclipse.cdt.core.model.IDeclaration#isConst() */ public boolean isConst() { - return false; + return isConst; } /** * @see org.eclipse.cdt.core.model.IDeclaration#isStatic() */ public boolean isStatic() { - return false; + return isStatic; } /** * @see org.eclipse.cdt.core.model.IDeclaration#isVolatile() */ public boolean isVolatile() { - return false; + return isVolatile; + } + + /** + * Sets the isConst. + * @param isConst The isConst to set + */ + public void setConst(boolean isConst) { + this.isConst = isConst; + } + + /** + * Sets the isStatic. + * @param isStatic The isStatic to set + */ + public void setStatic(boolean isStatic) { + this.isStatic = isStatic; + } + + /** + * Sets the isVolatile. + * @param isVolatile The isVolatile to set + */ + public void setVolatile(boolean isVolatile) { + this.isVolatile = isVolatile; } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Enumerator.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Enumerator.java new file mode 100644 index 00000000000..bd3a8c5b3df --- /dev/null +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/Enumerator.java @@ -0,0 +1,43 @@ +package org.eclipse.cdt.internal.core.model; + +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.IEnumerator; + +/********************************************************************** + * 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 +***********************************************************************/ +public class Enumerator extends SourceManipulation implements IEnumerator{ + + String constantExpression = ""; + + public Enumerator(ICElement parent, String name) { + super(parent, name, CElement.C_ENUMERATOR); + } + + protected CElementInfo createElementInfo () { + return new SourceManipulationInfo(this); + } + + /** + * @see org.eclipse.cdt.core.model.IEnumerator#getConstantExptrssion() + */ + public String getConstantExpression() { + return constantExpression; + } + + /** + * Sets the constantExpression. + * @param constantExpression The constantExpression to set + */ + public void setConstantExpression(String constantExpression) { + this.constantExpression = constantExpression; + } + +} diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementLabelProvider.java index 2842ccfb0c3..354a33e5f4b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementLabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/CElementLabelProvider.java @@ -8,7 +8,6 @@ package org.eclipse.cdt.ui; import org.eclipse.cdt.core.model.IBinary; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.IFunctionDeclaration; -import org.eclipse.cdt.core.model.IVariable; import org.eclipse.cdt.core.model.IVariableDeclaration; import org.eclipse.cdt.internal.ui.CElementImageProvider; import org.eclipse.cdt.internal.ui.ErrorTickAdornmentProvider; @@ -68,6 +67,15 @@ public class CElementLabelProvider extends LabelProvider { IFunctionDeclaration fdecl = (IFunctionDeclaration) celem; name = fdecl.getSignature(); break; + case ICElement.C_STRUCT: + case ICElement.C_ENUMERATION: + if(celem.getElementName() != null){ + name = celem.getElementName(); + } else { + IVariableDeclaration varDecl = (IVariableDeclaration) celem; + name = varDecl.getTypeName(); + } + break; default: name= celem.getElementName(); break;