A massive organize imports and formatting of the sources using default Eclipse code...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / Flags.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.core;
12
13 import net.sourceforge.phpdt.internal.compiler.env.IConstants;
14
15 /**
16  * Utility class for decoding modifier flags in Java elements.
17  * <p>
18  * This class provides static methods only; it is not intended to be
19  * instantiated or subclassed by clients.
20  * </p>
21  * <p>
22  * Note that the numeric values of these flags match the ones for class files as
23  * described in the Java Virtual Machine Specification. The AST class
24  * <code>Modifier</code> provides the same functionality as this class, only
25  * in the <code>net.sourceforge.phpdt.core.dom</code> package.
26  * </p>
27  * 
28  * @see IMember#getFlags
29  */
30 public final class Flags {
31         /**
32          * Constant representing the absence of any flag
33          * 
34          * @since 3.0
35          */
36         public static final int AccDefault = 0;
37
38         /**
39          * Public access flag. See The Java Virtual Machine Specification for more
40          * details.
41          * 
42          * @since 2.0
43          */
44         public static final int AccPublic = IConstants.AccPublic;
45
46         /**
47          * Private access flag. See The Java Virtual Machine Specification for more
48          * details.
49          * 
50          * @since 2.0
51          */
52         public static final int AccPrivate = IConstants.AccPrivate;
53
54         /**
55          * Protected access flag. See The Java Virtual Machine Specification for
56          * more details.
57          * 
58          * @since 2.0
59          */
60         public static final int AccProtected = IConstants.AccProtected;
61
62         /**
63          * Static access flag. See The Java Virtual Machine Specification for more
64          * details.
65          * 
66          * @since 2.0
67          */
68         public static final int AccStatic = IConstants.AccStatic;
69
70         /**
71          * Final access flag. See The Java Virtual Machine Specification for more
72          * details.
73          * 
74          * @since 2.0
75          */
76         public static final int AccFinal = IConstants.AccFinal;
77
78         /**
79          * Synchronized access flag. See The Java Virtual Machine Specification for
80          * more details.
81          * 
82          * @since 2.0
83          */
84         // public static final int AccSynchronized = IConstants.AccSynchronized;
85         /**
86          * Volatile property flag. See The Java Virtual Machine Specification for
87          * more details.
88          * 
89          * @since 2.0
90          */
91         // public static final int AccVolatile = IConstants.AccVolatile;
92         /**
93          * Transient property flag. See The Java Virtual Machine Specification for
94          * more details.
95          * 
96          * @since 2.0
97          */
98         // public static final int AccTransient = IConstants.AccTransient;
99         /**
100          * Native property flag. See The Java Virtual Machine Specification for more
101          * details.
102          * 
103          * @since 2.0
104          */
105         // public static final int AccNative = IConstants.AccNative;
106         /**
107          * Interface property flag. See The Java Virtual Machine Specification for
108          * more details.
109          * 
110          * @since 2.0
111          */
112         public static final int AccInterface = IConstants.AccInterface;
113
114         /**
115          * Abstract property flag. See The Java Virtual Machine Specification for
116          * more details.
117          * 
118          * @since 2.0
119          */
120         public static final int AccAbstract = IConstants.AccAbstract;
121
122         /**
123          * Strictfp property flag. See The Java Virtual Machine Specification for
124          * more details.
125          * 
126          * @since 2.0
127          */
128         // public static final int AccStrictfp = IConstants.AccStrictfp;
129         /**
130          * Super property flag. See The Java Virtual Machine Specification for more
131          * details.
132          * 
133          * @since 2.0
134          */
135         public static final int AccSuper = IConstants.AccSuper;
136
137         /**
138          * Synthetic property flag. See The Java Virtual Machine Specification for
139          * more details.
140          * 
141          * @since 2.0
142          */
143         // public static final int AccSynthetic = IConstants.AccSynthetic;
144         /**
145          * Deprecated property flag. See The Java Virtual Machine Specification for
146          * more details.
147          * 
148          * @since 2.0
149          */
150         public static final int AccDeprecated = IConstants.AccDeprecated;
151
152         /**
153          * Not instantiable.
154          */
155         private Flags() {
156         }
157
158         /**
159          * Returns whether the given integer includes the <code>abstract</code>
160          * modifier.
161          * 
162          * @param flags
163          *            the flags
164          * @return <code>true</code> if the <code>abstract</code> modifier is
165          *         included
166          */
167         public static boolean isAbstract(int flags) {
168                 return (flags & AccAbstract) != 0;
169         }
170
171         /**
172          * Returns whether the given integer includes the indication that the
173          * element is deprecated (<code>@deprecated</code> tag in Javadoc comment).
174          * 
175          * @param flags
176          *            the flags
177          * @return <code>true</code> if the element is marked as deprecated
178          */
179         public static boolean isDeprecated(int flags) {
180                 return (flags & AccDeprecated) != 0;
181         }
182
183         /**
184          * Returns whether the given integer includes the <code>final</code>
185          * modifier.
186          * 
187          * @param flags
188          *            the flags
189          * @return <code>true</code> if the <code>final</code> modifier is
190          *         included
191          */
192         public static boolean isFinal(int flags) {
193                 return (flags & AccFinal) != 0;
194         }
195
196         /**
197          * Returns whether the given integer includes the <code>interface</code>
198          * modifier.
199          * 
200          * @param flags
201          *            the flags
202          * @return <code>true</code> if the <code>interface</code> modifier is
203          *         included
204          * @since 2.0
205          */
206         public static boolean isInterface(int flags) {
207                 return (flags & AccInterface) != 0;
208         }
209
210         /**
211          * Returns whether the given integer includes the <code>native</code>
212          * modifier.
213          * 
214          * @param flags
215          *            the flags
216          * @return <code>true</code> if the <code>native</code> modifier is
217          *         included
218          */
219         // public static boolean isNative(int flags) {
220         // return (flags & AccNative) != 0;
221         // }
222         /**
223          * Returns whether the given integer includes the <code>private</code>
224          * modifier.
225          * 
226          * @param flags
227          *            the flags
228          * @return <code>true</code> if the <code>private</code> modifier is
229          *         included
230          */
231         public static boolean isPrivate(int flags) {
232                 return (flags & AccPrivate) != 0;
233         }
234
235         /**
236          * Returns whether the given integer includes the <code>protected</code>
237          * modifier.
238          * 
239          * @param flags
240          *            the flags
241          * @return <code>true</code> if the <code>protected</code> modifier is
242          *         included
243          */
244         public static boolean isProtected(int flags) {
245                 return (flags & AccProtected) != 0;
246         }
247
248         /**
249          * Returns whether the given integer includes the <code>public</code>
250          * modifier.
251          * 
252          * @param flags
253          *            the flags
254          * @return <code>true</code> if the <code>public</code> modifier is
255          *         included
256          */
257         public static boolean isPublic(int flags) {
258                 return (flags & AccPublic) != 0;
259         }
260
261         /**
262          * Returns whether the given integer includes the <code>static</code>
263          * modifier.
264          * 
265          * @param flags
266          *            the flags
267          * @return <code>true</code> if the <code>static</code> modifier is
268          *         included
269          */
270         public static boolean isStatic(int flags) {
271                 return (flags & AccStatic) != 0;
272         }
273
274         /**
275          * Returns whether the given integer includes the <code>strictfp</code>
276          * modifier.
277          * 
278          * @param flags
279          *            the flags
280          * @return <code>true</code> if the <code>strictfp</code> modifier is
281          *         included
282          */
283         // public static boolean isStrictfp(int flags) {
284         // return (flags & AccStrictfp) != 0;
285         // }
286         /**
287          * Returns whether the given integer includes the <code>synchronized</code>
288          * modifier.
289          * 
290          * @param flags
291          *            the flags
292          * @return <code>true</code> if the <code>synchronized</code> modifier
293          *         is included
294          */
295         // public static boolean isSynchronized(int flags) {
296         // return (flags & AccSynchronized) != 0;
297         // }
298         /**
299          * Returns whether the given integer includes the indication that the
300          * element is synthetic.
301          * 
302          * @param flags
303          *            the flags
304          * @return <code>true</code> if the element is marked synthetic
305          */
306         // public static boolean isSynthetic(int flags) {
307         // return (flags & AccSynthetic) != 0;
308         // }
309         /**
310          * Returns whether the given integer includes the <code>transient</code>
311          * modifier.
312          * 
313          * @param flags
314          *            the flags
315          * @return <code>true</code> if the <code>transient</code> modifier is
316          *         included
317          */
318         // public static boolean isTransient(int flags) {
319         // return (flags & AccTransient) != 0;
320         // }
321         /**
322          * Returns whether the given integer includes the <code>volatile</code>
323          * modifier.
324          * 
325          * @param flags
326          *            the flags
327          * @return <code>true</code> if the <code>volatile</code> modifier is
328          *         included
329          */
330         // public static boolean isVolatile(int flags) {
331         // return (flags & AccVolatile) != 0;
332         // }
333         /**
334          * Returns a standard string describing the given modifier flags. Only
335          * modifier flags are included in the output; the deprecated and synthetic
336          * flags are ignored if set.
337          * <p>
338          * The flags are output in the following order:
339          * 
340          * <pre>
341          *   <code>
342          * public
343          * </code> <code>
344          * protected
345          * </code> <code>
346          * private
347          * </code> 
348          *   <code>
349          * static
350          * </code> 
351          *   <code>
352          * abstract
353          * </code> <code>
354          * final
355          * </code> <code>
356          * native
357          * </code> <code>
358          * synchronized
359          * </code> <code>
360          * transient
361          * </code> <code>
362          * volatile
363          * </code> <code>
364          * strictfp
365          * </code>
366          * </pre>
367          * 
368          * This is a compromise between the orders specified in sections 8.1.1,
369          * 8.3.1, 8.4.3, 8.8.3, 9.1.1, and 9.3 of <em>The Java Language 
370          * Specification, Second Edition</em>
371          * (JLS2).
372          * </p>
373          * <p>
374          * Examples results:
375          * 
376          * <pre>
377          *        <code>
378          * &quot;public static final&quot;
379          * </code>
380          *        <code>
381          * &quot;private native&quot;
382          * </code>
383          * </pre>
384          * 
385          * </p>
386          * 
387          * @param flags
388          *            the flags
389          * @return the standard string representation of the given flags
390          */
391         public static String toString(int flags) {
392                 StringBuffer sb = new StringBuffer();
393
394                 if (isPublic(flags))
395                         sb.append("public "); //$NON-NLS-1$
396                 if (isProtected(flags))
397                         sb.append("protected "); //$NON-NLS-1$
398                 if (isPrivate(flags))
399                         sb.append("private "); //$NON-NLS-1$
400                 if (isStatic(flags))
401                         sb.append("static "); //$NON-NLS-1$
402                         // if (isAbstract(flags))
403                         // sb.append("abstract "); //$NON-NLS-1$
404                 if (isFinal(flags))
405                         sb.append("final "); //$NON-NLS-1$
406                         // if (isNative(flags))
407                         // sb.append("native "); //$NON-NLS-1$
408                         // if (isSynchronized(flags))
409                         // sb.append("synchronized "); //$NON-NLS-1$
410                         // if (isTransient(flags))
411                         // sb.append("transient "); //$NON-NLS-1$
412                         // if (isVolatile(flags))
413                         // sb.append("volatile "); //$NON-NLS-1$
414                         // if (isStrictfp(flags))
415                         // sb.append("strictfp "); //$NON-NLS-1$
416
417                 int len = sb.length();
418                 if (len == 0)
419                         return ""; //$NON-NLS-1$
420                 sb.setLength(len - 1);
421                 return sb.toString();
422         }
423 }