Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [cdt-patch] Namespace support, extern icon, JUnit test case.

Hi,
Patch has been updated.
I think Alain agrees with me that IStructure should extend
IVariableDeclaration because it is a declaration with a type that you can
set and get. 
I've added the CModelElementsTestStart.h that should be copied as a binary
file to
org.eclipse.cdt.ui.tests\model\org\eclipse\cdt\core\model\tests\resources\cf
iles

Thanks,
Hoda
-----Original Message-----
From: Schaefer, Doug [mailto:dschaefer@xxxxxxxxxxxx] 
Sent: Wednesday, April 02, 2003 9:54 PM
To: 'cdt-patch@xxxxxxxxxxx'
Subject: RE: [cdt-patch] Namespace support, extern icon, JUnit test case.

Hi Hoda, It looks like you and John are running into each other again.
Could you do an 'update' and resubmit the patch.

Also, in reference to Alain's previous question, could you give a quick two
line description of why you need IStructure to inherit from
IVariableDeclaration.  It's not obvious, but I'm sure you have a good reason
:-).

Thanks,
Doug Schaefer
Senior Staff Software Engineer
Rational Software - IBM Software Group
Ottawa (Kanata), Ontario, Canada
 

-----Original Message-----
From: Amer, Hoda [mailto:hamer@xxxxxxxxxxxx] 
Sent: Wednesday, April 02, 2003 3:36 PM
To: 'cdt-patch@xxxxxxxxxxx'
Subject: [cdt-patch] Namespace support, extern icon, JUnit test case.

Hi,
This patch adds:
- the support for namespaces in the NewModelBuilder. 
- an icon for extern variables.
- a JUnit test case for core model elements, including namespaces.
The enum_obj_gif should overwrite the existing file.

Thanks,
Hoda

_______________________________________________
cdt-patch mailing list
cdt-patch@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/cdt-patch

Index: parser/org/eclipse/cdt/internal/core/model/ICElementWrapper.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/model/ICElementWrapper.java,v
retrieving revision 1.3
diff -u -r1.3 ICElementWrapper.java
--- parser/org/eclipse/cdt/internal/core/model/ICElementWrapper.java	1 Apr 2003 18:52:37 -0000	1.3
+++ parser/org/eclipse/cdt/internal/core/model/ICElementWrapper.java	3 Apr 2003 15:02:26 -0000
@@ -1,5 +1,6 @@
 package org.eclipse.cdt.internal.core.model;
 
+import org.eclipse.cdt.core.model.ICElement;
 import org.eclipse.cdt.core.model.IParent;
 
 /**
@@ -12,6 +13,7 @@
  */
 public interface ICElementWrapper {
 
-	public IParent getElement();
-	public void setElement (IParent item);
+	public ICElement getElement();
+	public void setElement (ICElement item);
+	public IParent getParent();
 }
Index: parser/org/eclipse/cdt/internal/core/model/NamespaceWrapper.java
===================================================================
RCS file: parser/org/eclipse/cdt/internal/core/model/NamespaceWrapper.java
diff -N parser/org/eclipse/cdt/internal/core/model/NamespaceWrapper.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ parser/org/eclipse/cdt/internal/core/model/NamespaceWrapper.java	3 Apr 2003 15:02:26 -0000
@@ -0,0 +1,67 @@
+package org.eclipse.cdt.internal.core.model;
+
+import org.eclipse.cdt.core.model.IParent;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.internal.core.parser.util.Name;
+
+/**********************************************************************
+ * Created on Apr 1, 2003
+ *
+ * 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 NamespaceWrapper implements ICElementWrapper{
+	private Name name; 
+	private final IParent parent;
+	private ICElement element;   
+	
+	public NamespaceWrapper( IParent incoming)
+	{
+		this.parent= incoming;
+	}
+
+	/**
+	 * Returns the name.
+	 * @return Name
+	 */
+	public Name getName() {
+		return name;
+	}
+
+	/**
+	 * Returns the parent.
+	 * @return IParent
+	 */
+	public IParent getParent() {
+		return parent;
+	}
+
+	/**
+	 * Sets the name.
+	 * @param name The name to set
+	 */
+	public void setName(Name name) {
+		this.name = name;
+	}
+
+	/**
+	 * @see org.eclipse.cdt.internal.core.model.ICElementWrapper#getElement()
+	 */
+	public ICElement getElement() {
+		return element;
+	}
+
+	/**
+	 * @see org.eclipse.cdt.internal.core.model.ICElementWrapper#setElement(org.eclipse.cdt.core.model.IParent)
+	 */
+	public void setElement(ICElement item) {
+		element = item;
+	}
+
+}
Index: parser/org/eclipse/cdt/internal/core/model/NewModelBuilder.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/model/NewModelBuilder.java,v
retrieving revision 1.18
diff -u -r1.18 NewModelBuilder.java
--- parser/org/eclipse/cdt/internal/core/model/NewModelBuilder.java	3 Apr 2003 02:59:58 -0000	1.18
+++ parser/org/eclipse/cdt/internal/core/model/NewModelBuilder.java	3 Apr 2003 15:02:26 -0000
@@ -15,6 +15,7 @@
 import java.util.List;
 
 import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.IParent;
 import org.eclipse.cdt.internal.core.parser.IParserCallback;
 import org.eclipse.cdt.internal.core.parser.Token;
 import org.eclipse.cdt.internal.core.parser.util.AccessSpecifier;
@@ -135,14 +136,15 @@
 org.eclipse.cdt.internal.core.newparser.IParserCallback#beginSimpleDeclaration(Token)
 	 */
 	public Object simpleDeclarationBegin(Object container) {
-		ICElementWrapper wrapper = (ICElementWrapper)container; 
-		Object parent = wrapper.getElement();
+		ICElementWrapper wrapper = (ICElementWrapper)container;
+		// Assuming that the parent is the container's element 
+		IParent parent = (IParent)wrapper.getElement();
 		SimpleDeclarationWrapper result = new SimpleDeclarationWrapper();
+		result.setParent( parent );
+		// A special case to transfere the visibility
 		if( wrapper instanceof SimpleDeclarationWrapper ){
-			result.setParent( wrapper.getElement() );
 			result.setCurrentVisibility(((SimpleDeclarationWrapper)wrapper).getCurrentVisibility());
-		} else if ( wrapper instanceof TranslationUnitWrapper )
-			result.setParent( (TranslationUnit)wrapper.getElement());
+		}
 		return result;  	
 	}
 	
@@ -354,8 +356,9 @@
 		elem.setElementName( elementName );
 		if( wrapper.getName() != null )
 		{ 	
-			elem.setIdPos(wrapper.getName().getStartOffset(), wrapper.getName().length());
-			elem.setPos(wrapper.getName().getStartOffset(), wrapper.getName().length());
+			elem.setTypeName( wrapper.getClassKind().getImage() );
+			elem.setIdPos(wrapper.getName().getStartOffset(), elementName.length());
+			elem.setPos(wrapper.getName().getStartOffset(), elementName.length());
 		}
 		else
 		{
@@ -549,21 +552,37 @@
 	 * @see org.eclipse.cdt.internal.core.parser.IParserCallback#namespaceDeclarationBegin(java.lang.Object)
 	 */
 	public Object namespaceDefinitionBegin(Object container) {
-		// until Namespaces are made part of the code model, just return the container object
-		return container; 
+
+		ICElementWrapper c = (ICElementWrapper)container; 
+		NamespaceWrapper wrapper = new NamespaceWrapper((IParent)c.getElement());		
+		return wrapper;  	
 	}
 
 	/* (non-Javadoc)
 	 * @see org.eclipse.cdt.internal.core.parser.IParserCallback#namespaceDeclarationId(java.lang.Object)
 	 */
 	public void namespaceDefinitionId(Object namespace) {
-		// until namespaceDefinitionBegin is updated to do more than return its container, do nothing
+		// set wrapper name to current name
+		NamespaceWrapper wrapper = (NamespaceWrapper)namespace;
+		wrapper.setName( currName );
+		
+		// create the new element
+		String namespaceName = wrapper.getName().toString(); 
+		Parent realParent = (Parent)wrapper.getParent();
+		Namespace newNameSpace = new Namespace( (ICElement)realParent, namespaceName );
+		wrapper.setElement(newNameSpace);
+		realParent.addChild( newNameSpace );
+
+		// set the positions
+		newNameSpace.setIdPos(wrapper.getName().getStartOffset(), namespaceName.length());
+		newNameSpace.setPos(wrapper.getName().getStartOffset(), namespaceName.length());		
 	}
 
 	/* (non-Javadoc)
 	 * @see org.eclipse.cdt.internal.core.parser.IParserCallback#namespaceDeclarationAbort(java.lang.Object)
 	 */
 	public void namespaceDefinitionAbort(Object namespace) {
+		namespace = null;
 	}
 
 	/* (non-Javadoc)
Index: parser/org/eclipse/cdt/internal/core/model/SimpleDeclarationWrapper.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/model/SimpleDeclarationWrapper.java,v
retrieving revision 1.15
diff -u -r1.15 SimpleDeclarationWrapper.java
--- parser/org/eclipse/cdt/internal/core/model/SimpleDeclarationWrapper.java	3 Apr 2003 02:59:58 -0000	1.15
+++ parser/org/eclipse/cdt/internal/core/model/SimpleDeclarationWrapper.java	3 Apr 2003 15:02:25 -0000
@@ -3,7 +3,9 @@
 import java.util.LinkedList;
 import java.util.List;
 
+import org.eclipse.cdt.core.model.INamespace;
 import org.eclipse.cdt.core.model.IParent;
+import org.eclipse.cdt.core.model.ICElement;
 import org.eclipse.cdt.core.model.IStructure;
 import org.eclipse.cdt.core.model.ITranslationUnit;
 import org.eclipse.cdt.internal.core.parser.Token;
@@ -17,7 +19,7 @@
  */
 public class SimpleDeclarationWrapper extends DeclSpecifier implements DeclSpecifier.Container, ICElementWrapper {
 
-	private IParent element = null; 
+	private ICElement element = null; 
 	private IParent parent = null; 
 
 	private Name name = null;
@@ -36,7 +38,7 @@
 	 * Returns the item.
 	 * @return CElement
 	 */
-	public IParent getElement() {
+	public ICElement getElement() {
 		return element;
 	}
 
@@ -44,8 +46,8 @@
 	 * Sets the item.
 	 * @param item The item to set
 	 */
-	public void setElement (IParent item) {
-		this.element = (IParent)item;
+	public void setElement (ICElement item) {
+		this.element = item;
 	}
 
 	/**
@@ -90,7 +92,8 @@
 				{
 					declaration = createField( parentElement, declaratorName ); 
 				}
-				else if( parentElement instanceof ITranslationUnit )
+				else if(( parentElement instanceof ITranslationUnit ) 
+					  || ( parentElement instanceof INamespace ))
 				{
 					if(isExtern())
 					{
@@ -112,10 +115,18 @@
 				// this is a function or a method
 				if( parentElement instanceof IStructure )
 				{
-					declaration = createMethodDeclaration( parentElement, declaratorName, parameters ); 
+					if (isFunctionDefinition())
+					{
+						declaration = createMethod( parentElement, declaratorName, parameters ); 
+					}
+					else
+					{
+						declaration = createMethodDeclaration( parentElement, declaratorName, parameters ); 
+					}
 		
 				}
-				else if( parentElement instanceof ITranslationUnit )
+				else if(( parentElement instanceof ITranslationUnit ) 
+						|| ( parentElement instanceof INamespace ))
 				{
 					if (isFunctionDefinition())
 					{
Index: parser/org/eclipse/cdt/internal/core/model/TranslationUnitWrapper.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/model/TranslationUnitWrapper.java,v
retrieving revision 1.3
diff -u -r1.3 TranslationUnitWrapper.java
--- parser/org/eclipse/cdt/internal/core/model/TranslationUnitWrapper.java	1 Apr 2003 18:52:37 -0000	1.3
+++ parser/org/eclipse/cdt/internal/core/model/TranslationUnitWrapper.java	3 Apr 2003 15:02:26 -0000
@@ -1,5 +1,6 @@
 package org.eclipse.cdt.internal.core.model;
 
+import org.eclipse.cdt.core.model.ICElement;
 import org.eclipse.cdt.core.model.IParent;
 
 /**
@@ -17,18 +18,25 @@
 	/**
 	 * @see org.eclipse.cdt.internal.core.model.IWrapper#getElement()
 	 */
-	public IParent getElement() {
+	public ICElement getElement() {
 		return unit;
 	}
 	/**
 	 * @see org.eclipse.cdt.internal.core.model.IWrapper#setElement(java.lang.Object)
 	 */
-	public void setElement(IParent item) {
+	public void setElement(ICElement item) {
 		unit = (TranslationUnit)item; 
 	}
 	
 	public TranslationUnitWrapper( )
 	{
+	}
+
+	/**
+	 * @see org.eclipse.cdt.internal.core.model.ICElementWrapper#getParent()
+	 */
+	public IParent getParent() {
+		return null;
 	}
 
 }
Index: icons/full/obj16/enum_obj.gif
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui/icons/full/obj16/enum_obj.gif,v
retrieving revision 1.1
diff -u -r1.1 enum_obj.gif
Binary files /tmp/cvs5WrXZg and enum_obj.gif differ
Index: icons/full/obj16/var_declaration_obj.gif
===================================================================
RCS file: icons/full/obj16/var_declaration_obj.gif
diff -N icons/full/obj16/var_declaration_obj.gif
Binary files /dev/null and var_declaration_obj.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.11
diff -u -r1.11 CElementImageProvider.java
--- src/org/eclipse/cdt/internal/ui/CElementImageProvider.java	3 Apr 2003 04:29:59 -0000	1.11
+++ src/org/eclipse/cdt/internal/ui/CElementImageProvider.java	3 Apr 2003 15:02:48 -0000
@@ -251,6 +251,9 @@
 			case ICElement.C_FUNCTION:
 				return CPluginImages.DESC_OBJS_FUNCTION;
 		
+			case ICElement.C_VARIABLE_DECLARATION:
+				return CPluginImages.DESC_OBJS_VAR_DECLARARION;
+			
 			case ICElement.C_FUNCTION_DECLARATION:
 				return CPluginImages.DESC_OBJS_DECLARARION;
 
@@ -259,59 +262,13 @@
 
 			case ICElement.C_MACRO:
 				return CPluginImages.DESC_OBJS_MACRO;
-		}
-		return null;
-	}
-	
-	public ImageDescriptor getCElementImageDescriptor(int type) {
-		switch (type) {
-			case ICElement.C_VCONTAINER:
-				return CPluginImages.DESC_OBJS_CONTAINER;
-
-			case ICElement.C_UNIT:
-				return CPluginImages.DESC_OBJS_TUNIT;
-
-			case ICElement.C_STRUCT:
-				return CPluginImages.DESC_OBJS_STRUCT;
-				
-			case ICElement.C_CLASS:
-				return CPluginImages.DESC_OBJS_CLASS;
-				
-			case ICElement.C_UNION:
-				return CPluginImages.DESC_OBJS_UNION;
-
-			case ICElement.C_TYPEDEF:
-				return CPluginImages.DESC_OBJS_TYPEDEF;
-
-			case ICElement.C_ENUMERATION:
-				return CPluginImages.DESC_OBJS_ENUMERATION;
-
-			case ICElement.C_ENUMERATOR:
-				return CPluginImages.DESC_OBJS_ENUMERATOR;
-
-			case ICElement.C_FIELD:
-				return CPluginImages.DESC_OBJS_PUBLIC_FIELD;
-
-			case ICElement.C_VARIABLE:
-				return CPluginImages.DESC_OBJS_FIELD;
-
-			case ICElement.C_METHOD: // assumed public
-				return CPluginImages.DESC_OBJS_PUBLIC_METHOD;
 				
-			case ICElement.C_FUNCTION:
-			case ICElement.C_FUNCTION_DECLARATION:
-				return CPluginImages.DESC_OBJS_FUNCTION;
-
-			case ICElement.C_INCLUDE:
-				return CPluginImages.DESC_OBJS_INCLUDE;
-
-			case ICElement.C_MACRO:
-				return CPluginImages.DESC_OBJS_MACRO;
+			case ICElement.C_NAMESPACE:
+				return CPluginImages.DESC_OBJS_CONTAINER;
+			
 		}
-		System.out.println("Unknown base object ype " + type);
-		return CPluginImages.DESC_OBJS_MACRO;
-		//return null;
-	}
+		return null;
+	}	
 
 
 	// ---- Methods to compute the adornments 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.8
diff -u -r1.8 CPluginImages.java
--- src/org/eclipse/cdt/internal/ui/CPluginImages.java	3 Apr 2003 04:29:59 -0000	1.8
+++ src/org/eclipse/cdt/internal/ui/CPluginImages.java	3 Apr 2003 15:02:48 -0000
@@ -58,6 +58,7 @@
 	public static final String IMG_OBJS_PROTECTED_FIELD= NAME_PREFIX + "field_protected_obj.gif";
 	public static final String IMG_OBJS_PRIVATE_FIELD= NAME_PREFIX + "field_private_obj.gif";	
 	public static final String IMG_OBJS_DECLARATION= NAME_PREFIX + "cdeclaration_obj.gif";
+	public static final String IMG_OBJS_VAR_DECLARATION= NAME_PREFIX + "var_declaration_obj.gif";
 	public static final String IMG_OBJS_INCLUDE= NAME_PREFIX + "include_obj.gif";
 	public static final String IMG_OBJS_MACRO= NAME_PREFIX + "define_obj.gif";
 	public static final String IMG_OBJS_TUNIT= NAME_PREFIX + "c_file_obj.gif";
@@ -90,6 +91,7 @@
 	public static final ImageDescriptor DESC_OBJS_PROTECTED_FIELD= createManaged(T_OBJ, IMG_OBJS_PROTECTED_FIELD);
 	public static final ImageDescriptor DESC_OBJS_PRIVATE_FIELD= createManaged(T_OBJ, IMG_OBJS_PRIVATE_FIELD);			
 	public static final ImageDescriptor DESC_OBJS_DECLARARION= createManaged(T_OBJ, IMG_OBJS_DECLARATION);
+	public static final ImageDescriptor DESC_OBJS_VAR_DECLARARION= createManaged(T_OBJ, IMG_OBJS_VAR_DECLARATION);
 	public static final ImageDescriptor DESC_OBJS_INCLUDE= createManaged(T_OBJ, IMG_OBJS_INCLUDE);
 	public static final ImageDescriptor DESC_OBJS_MACRO= createManaged(T_OBJ, IMG_OBJS_MACRO);
 	public static final ImageDescriptor DESC_OBJS_TUNIT= createManaged(T_OBJ, IMG_OBJS_TUNIT);
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.8
diff -u -r1.8 CElementLabelProvider.java
--- src/org/eclipse/cdt/ui/CElementLabelProvider.java	1 Apr 2003 19:11:44 -0000	1.8
+++ src/org/eclipse/cdt/ui/CElementLabelProvider.java	3 Apr 2003 15:02:47 -0000
@@ -76,6 +76,7 @@
 					name = fDecl.getSignature();		
 				break;
 				case ICElement.C_STRUCT:
+				case ICElement.C_UNION:
 				case ICElement.C_ENUMERATION:
 					if((celem.getElementName() != null) && (celem.getElementName().length() > 0)){
 						name = celem.getElementName();
Index: model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java
===================================================================
RCS file: model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java
diff -N model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java	3 Apr 2003 15:03:08 -0000
@@ -0,0 +1,113 @@
+package org.eclipse.cdt.core.model.tests;
+
+/**********************************************************************
+ * 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 java.io.FileInputStream;
+import java.util.ArrayList;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.model.ICElement;
+import org.eclipse.cdt.core.model.ICProject;
+import org.eclipse.cdt.core.model.IField;
+import org.eclipse.cdt.core.model.IMember;
+import org.eclipse.cdt.core.model.IMethod;
+import org.eclipse.cdt.core.model.INamespace;
+import org.eclipse.cdt.core.model.IStructure;
+import org.eclipse.cdt.internal.core.model.TranslationUnit;
+import org.eclipse.cdt.testplugin.CProjectHelper;
+import org.eclipse.cdt.testplugin.TestPluginLauncher;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+
+public class CModelElementsTests extends TestCase {	
+	private ICProject fCProject;
+	private IFile headerFile;
+	private NullProgressMonitor monitor;
+		
+	public static void main(String[] args) {
+		TestPluginLauncher.run(TestPluginLauncher.getLocationFromProperties(), WorkingCopyTests.class, args);
+	}
+		
+	public static Test suite() {
+		TestSuite suite= new TestSuite();
+		suite.addTest(new CModelElementsTests("testCModelElements"));
+		return suite;
+	}		
+		
+	public CModelElementsTests(String name) {
+		super(name);
+	}
+		
+	protected void setUp() throws Exception {
+		monitor = new NullProgressMonitor();
+		String pluginRoot=org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.ui.tests").find(new Path("/")).getFile();
+	
+		fCProject= CProjectHelper.createCProject("TestProject1", "bin");
+		headerFile = fCProject.getProject().getFile("CModelElementsTest.h");
+		if (!headerFile.exists()) {
+			try{
+				FileInputStream fileIn = new FileInputStream(pluginRoot+ "model/org/eclipse/cdt/core/model/tests/resources/cfiles/CModelElementsTestStart.h"); 
+				headerFile.create(fileIn,false, monitor);        
+			} catch (CoreException e) {
+				e.printStackTrace();
+			}
+		}
+		CCorePlugin.getDefault().setUseNewParser(true);
+
+	}
+	
+	protected void tearDown() throws Exception {
+		CProjectHelper.delete(fCProject);
+	}	
+			
+	public void testCModelElements(){
+		TranslationUnit tu = new TranslationUnit(fCProject, headerFile);
+		// parse the translation unit to get the elements tree		
+		tu.parse();
+		
+		// tu ---> namespace MyPackage
+		ArrayList tuPackages = tu.getChildrenOfType(ICElement.C_NAMESPACE);
+		INamespace namespace = (INamespace) tuPackages.get(0);
+		assertEquals(namespace.getElementName(), new String("MyPackage"));
+		
+		// MyPackage ---> class Hello
+		ArrayList nsClassChildren = namespace.getChildrenOfType(ICElement.C_CLASS);		
+		IStructure classHello = (IStructure) nsClassChildren.get(0);
+		assertEquals(classHello.getElementName(), new String("Hello"));
+		
+		// Hello --> int x
+		ArrayList helloFieldChildren = classHello.getChildrenOfType(ICElement.C_FIELD);
+		IField intX = (IField) helloFieldChildren.get(0);
+		assertEquals(intX.getElementName(), new String("x"));
+		int visibility = intX.getVisibility(); 
+		if (visibility != IMember.V_PROTECTED)
+			fail("visibility should be protected!");
+		
+		
+		// Hello ---> void setX(int X)
+		ArrayList helloMethodChildren = classHello.getChildrenOfType(ICElement.C_METHOD);
+		IMethod setX = (IMethod) helloMethodChildren.get(0);
+		assertEquals(setX.getElementName(), new String("setX"));
+		int setXNumOfParam = setX.getNumberOfParameters();
+		if(setXNumOfParam != 1)
+			fail("setX should have one parameter!");
+		String[] setXParamTypes = setX.getParameterTypes();
+		String firstParamType = setXParamTypes[0];
+		assertEquals(firstParamType, new String("int")); 
+	}
+
+}
Index: model/org/eclipse/cdt/core/model/tests/resources/cfiles/CModelElementsTestStart.h
===================================================================
RCS file: model/org/eclipse/cdt/core/model/tests/resources/cfiles/CModelElementsTestStart.h
diff -N model/org/eclipse/cdt/core/model/tests/resources/cfiles/CModelElementsTestStart.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ model/org/eclipse/cdt/core/model/tests/resources/cfiles/CModelElementsTestStart.h	3 Apr 2003 15:03:08 -0000
@@ -0,0 +1,11 @@
+#include <stdio.h>
+
+namespace MyPackage{
+	class Hello{
+	protected:
+		int x;
+		void setX(int X){
+			x = X;
+		};
+	};
+};
\ No newline at end of file

Attachment: var_declaration_obj.gif
Description: GIF image

Attachment: enum_obj.gif
Description: GIF image

Attachment: CModelElementsTestStart.h
Description: Binary data


Back to the top