Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: eacc6630c2dedf4e17b12dd223eb22bd3dbe360e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package org.eclipse.cdt.internal.core.model;

import java.util.LinkedList;
import java.util.List;

import org.eclipse.cdt.core.model.IStructure;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.core.newparser.util.DeclSpecifier;
import org.eclipse.cdt.internal.core.newparser.util.DeclarationSpecifier;

/**
 * @author jcamelon
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */
public class SimpleDeclarationWrapper extends DeclSpecifier implements DeclarationSpecifier.Container, ICElementWrapper {

	private CElement element = null; 
	private CElement parent = null; 

	public SimpleDeclarationWrapper( CElement item )
	{
		this.element = item; 
	}
	
	public SimpleDeclarationWrapper()
	{
	}
	
	/**
	 * Returns the item.
	 * @return CElement
	 */
	public CElement getElement() {
		return element;
	}

	/**
	 * Sets the item.
	 * @param item The item to set
	 */
	public void setElement (CElement item) {
		this.element = (CElement)item;
	}

	/**
	 * Returns the parent.
	 * @return CElement
	 */
	public CElement getParent() {
		return parent;
	}

	/**
	 * Sets the parent.
	 * @param parent The parent to set
	 */
	public void setParent(CElement parent) {
		this.parent = parent;
	}
	
	public void createElements()
	{
		// creates the appropriate C Elements 
		List declaratorList = getDeclarators();
		Declarator [] declarators = (Declarator []) declaratorList.toArray( new Declarator[ declaratorList.size() ] );
		CElement parentElement = getParent(); 
		
		for( int i = 0; i < declarators.length; ++i )
		{
			Declarator currentDeclarator = declarators[i];
			CElement declaration  = null;
			
			// instantiate the right element   
			List clause =currentDeclarator.getParameterDeclarationClause(); 
			if( clause == null )
			{
				//	this is an attribute or a varaible
				if( parentElement instanceof IStructure )
				{
					declaration = new Field( parentElement, currentDeclarator.getName().toString() ); 
				}
				else if( parentElement instanceof ITranslationUnit )
				{
					declaration = new Variable( parentElement, currentDeclarator.getName().toString() );
				}
			}
			else
			{
				// this is a function or a method
				if( parentElement instanceof IStructure )
				{
					declaration = new Method( parentElement, currentDeclarator.getName().toString() ); 
		
				}
				else if( parentElement instanceof ITranslationUnit )
				{
					declaration = new FunctionDeclaration( parentElement, currentDeclarator.getName().toString() ); 
				}
				
				Parameter [] parameters = (Parameter []) clause.toArray( new Parameter[ clause.size() ]);
				
				for( int j = 0; j< parameters.length; ++j )
				{
					Parameter parm = parameters[j];
					 
				}
				
			}
			
			// hook up the offsets
			declaration.setIdPos( currentDeclarator.getName().getEndOffset() - 2,currentDeclarator.getName().toString().length()); 
			declaration.setPos( currentDeclarator.getName().getEndOffset(), currentDeclarator.getName().toString().length() );
			
			// add to parent
			parentElement.addChild( declaration ); 	
		}
		
	}
	
	List declarators = new LinkedList();
	
	public void addDeclarator( Object in )
	{
		declarators.add( in ); 
	}
		
	public List getDeclarators()
	{
		return declarators; 
	}
	
	DeclarationSpecifier declSpec = null; 

	/**
	 * @see org.eclipse.cdt.internal.core.dom.DeclarationSpecifier.CElementWrapper#getDeclSpecifier()
	 */
	public DeclarationSpecifier getDeclSpecifier() {
		if( declSpec == null )
			declSpec = new DeclarationSpecifier(); 
			
		return declSpec; 
	}

	/**
	 * @see org.eclipse.cdt.internal.core.dom.DeclarationSpecifier.CElementWrapper#setDeclSpecifier(org.eclipse.cdt.internal.core.dom.DeclarationSpecifier)
	 */
	public void setDeclSpecifier(DeclarationSpecifier in) {
		declSpec = in; 
	}
	
}

Back to the top