|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 * Representation of a parameter parsed from source |
|
17 * |
|
18 */ |
|
19 package com.nokia.tracecompiler.source; |
|
20 |
|
21 import java.util.ArrayList; |
|
22 |
|
23 /** |
|
24 * Representation of a parameter parsed from source |
|
25 * |
|
26 */ |
|
27 public class SourceParameter implements ParsedType { |
|
28 |
|
29 /** |
|
30 * Parameter qualifiers |
|
31 */ |
|
32 private ArrayList<String> qualifiers; |
|
33 |
|
34 /** |
|
35 * Parameter type |
|
36 */ |
|
37 private String type; |
|
38 |
|
39 /** |
|
40 * Parameter name |
|
41 */ |
|
42 private String name; |
|
43 |
|
44 /** |
|
45 * Flag specifying if parameter is reference |
|
46 */ |
|
47 private boolean isReference; |
|
48 |
|
49 /** |
|
50 * Number of pointers in parameter |
|
51 */ |
|
52 private int pointerCount; |
|
53 |
|
54 /** |
|
55 * The location of this parameter in source |
|
56 */ |
|
57 private SourceLocation location; |
|
58 |
|
59 /** |
|
60 * Gets the parameter type |
|
61 * |
|
62 * @return the type |
|
63 */ |
|
64 public String getType() { |
|
65 return type; |
|
66 } |
|
67 |
|
68 /** |
|
69 * Gets the parameter name or null if parameter does not have a name |
|
70 * |
|
71 * @return the name |
|
72 */ |
|
73 public String getName() { |
|
74 return name; |
|
75 } |
|
76 |
|
77 /** |
|
78 * Checks if parameter is pointer (*) or pointer reference (*&) |
|
79 * |
|
80 * @return true if pointer, false if not |
|
81 */ |
|
82 public boolean isPointer() { |
|
83 return pointerCount > 0; |
|
84 } |
|
85 |
|
86 /** |
|
87 * Gets the number of pointers |
|
88 * |
|
89 * @return the number of pointers |
|
90 */ |
|
91 public int getPointerCount() { |
|
92 return pointerCount; |
|
93 } |
|
94 |
|
95 /** |
|
96 * Checks if a parameter is referece (&) or pointer reference (*&) |
|
97 * |
|
98 * @return true if reference, false if not |
|
99 */ |
|
100 public boolean isReference() { |
|
101 return isReference; |
|
102 } |
|
103 |
|
104 /** |
|
105 * Checks if paraemter is pointer (*), but not pointer reference (*&). Equal |
|
106 * to isPointer() && !isReference() |
|
107 * |
|
108 * @return true if pointer, but not reference |
|
109 */ |
|
110 public boolean isPlainPointer() { |
|
111 return pointerCount > 0 && !isReference; |
|
112 } |
|
113 |
|
114 /** |
|
115 * Checks if parameter is reference (&), but not pointer reference (*&). |
|
116 * Equal to !isPointer() && isReference() |
|
117 * |
|
118 * @return true if reference to value |
|
119 */ |
|
120 public boolean isPlainReference() { |
|
121 return pointerCount == 0 && isReference; |
|
122 } |
|
123 |
|
124 /** |
|
125 * Checks if parameter is a reference to a pointer (*&). Equal to |
|
126 * isPointer() && isReference() |
|
127 * |
|
128 * @return true if reference to a pointer |
|
129 */ |
|
130 public boolean isPointerReference() { |
|
131 return pointerCount > 0 && isReference; |
|
132 } |
|
133 |
|
134 /** |
|
135 * Checks if parameter is pointer (*) or reference (&). Equal to isPointer() || |
|
136 * isReference() |
|
137 * |
|
138 * @return true if pointer or reference |
|
139 */ |
|
140 public boolean isPointerOrReference() { |
|
141 return pointerCount > 0 || isReference; |
|
142 } |
|
143 |
|
144 /** |
|
145 * Checks if parameter type equals given type |
|
146 * |
|
147 * @param type |
|
148 * the type to be checked |
|
149 * @return true if types match |
|
150 */ |
|
151 public boolean typeEquals(String type) { |
|
152 return this.type != null && type != null && this.type.equals(type); |
|
153 } |
|
154 |
|
155 /** |
|
156 * Returns the source reference of this parameter |
|
157 * |
|
158 * @return the source reference |
|
159 */ |
|
160 public SourceLocation getSourceLocation() { |
|
161 return location; |
|
162 } |
|
163 |
|
164 /** |
|
165 * Sets the parameter type |
|
166 * |
|
167 * @param type |
|
168 * the new type |
|
169 */ |
|
170 void setType(String type) { |
|
171 this.type = type; |
|
172 } |
|
173 |
|
174 /** |
|
175 * Sets the parameter name |
|
176 * |
|
177 * @param name |
|
178 * the new name |
|
179 */ |
|
180 void setName(String name) { |
|
181 this.name = name; |
|
182 } |
|
183 |
|
184 /** |
|
185 * Sets the reference flag |
|
186 */ |
|
187 void setReference() { |
|
188 isReference = true; |
|
189 } |
|
190 |
|
191 /** |
|
192 * Increments the pointer count |
|
193 */ |
|
194 void addPointer() { |
|
195 pointerCount++; |
|
196 } |
|
197 |
|
198 /** |
|
199 * Adds a qualifier to this parameter |
|
200 * |
|
201 * @param type |
|
202 * the qualifier type |
|
203 */ |
|
204 void addQualifier(String type) { |
|
205 if (qualifiers == null) { |
|
206 qualifiers = new ArrayList<String>(); |
|
207 } |
|
208 qualifiers.add(type); |
|
209 } |
|
210 |
|
211 /** |
|
212 * Sets the source location of this parameter |
|
213 * |
|
214 * @param location |
|
215 * the location |
|
216 */ |
|
217 void setSourceLocation(SourceLocation location) { |
|
218 this.location = location; |
|
219 } |
|
220 |
|
221 /** |
|
222 * Checks if a qualifier exists |
|
223 * |
|
224 * @param qualifier |
|
225 * the qualifier to be checked |
|
226 * @return true if it exists |
|
227 */ |
|
228 public boolean hasQualifier(String qualifier) { |
|
229 boolean retval; |
|
230 if (qualifiers != null) { |
|
231 retval = qualifiers.contains(qualifier); |
|
232 } else { |
|
233 retval = false; |
|
234 } |
|
235 return retval; |
|
236 } |
|
237 |
|
238 } |