Changes:
[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
17 /**
18  * Utility class for decoding modifier flags in Java elements.
19  * <p>
20  * This class provides static methods only; it is not intended to be
21  * instantiated or subclassed by clients.
22  * </p>
23  * <p>
24  * Note that the numeric values of these flags match the ones for class files
25  * as described in the Java Virtual Machine Specification. The AST class
26  * <code>Modifier</code> provides the same functionality as this class, only in
27  * the <code>org.eclipse.jdt.core.dom</code> package.
28  * </p>
29  *
30  * @see IMember#getFlags
31  */
32 public final class Flags {
33
34         /**
35          * Public access flag. See The Java Virtual Machine Specification for more details.
36          * @since 2.0
37          */
38         public static final int AccPublic = IConstants.AccPublic;
39         /**
40          * Private access flag. See The Java Virtual Machine Specification for more details.
41          * @since 2.0
42          */
43         public static final int AccPrivate = IConstants.AccPrivate;
44         /**
45          * Protected access flag. See The Java Virtual Machine Specification for more details.
46          * @since 2.0
47          */
48         public static final int AccProtected = IConstants.AccProtected;
49         /**
50          * Static access flag. See The Java Virtual Machine Specification for more details.
51          * @since 2.0
52          */
53         public static final int AccStatic = IConstants.AccStatic;
54         /**
55          * Final access flag. See The Java Virtual Machine Specification for more details.
56          * @since 2.0
57          */
58         public static final int AccFinal = IConstants.AccFinal;
59         /**
60          * Synchronized access flag. See The Java Virtual Machine Specification for more details.
61          * @since 2.0
62          */
63 //      public static final int AccSynchronized = IConstants.AccSynchronized;
64         /**
65          * Volatile property flag. See The Java Virtual Machine Specification for more details.
66          * @since 2.0
67          */
68 //      public static final int AccVolatile = IConstants.AccVolatile;
69         /**
70          * Transient property flag. See The Java Virtual Machine Specification for more details.
71          * @since 2.0
72          */
73 //      public static final int AccTransient = IConstants.AccTransient;
74         /**
75          * Native property flag. See The Java Virtual Machine Specification for more details.
76          * @since 2.0
77          */
78 //      public static final int AccNative = IConstants.AccNative;
79         /**
80          * Interface property flag. See The Java Virtual Machine Specification for more details.
81          * @since 2.0
82          */
83 //      public static final int AccInterface = IConstants.AccInterface;
84         /**
85          * Abstract property flag. See The Java Virtual Machine Specification for more details.
86          * @since 2.0
87          */
88 //      public static final int AccAbstract = IConstants.AccAbstract;
89         /**
90          * Strictfp property flag. See The Java Virtual Machine Specification for more details.
91          * @since 2.0
92          */
93 //      public static final int AccStrictfp = IConstants.AccStrictfp;
94         /**
95          * Super property flag. See The Java Virtual Machine Specification for more details.
96          * @since 2.0
97          */
98         public static final int AccSuper = IConstants.AccSuper;
99         /**
100          * Synthetic property flag. See The Java Virtual Machine Specification for more details.
101          * @since 2.0
102          */
103 //      public static final int AccSynthetic = IConstants.AccSynthetic;
104         /**
105          * Deprecated property flag. See The Java Virtual Machine Specification for more details.
106          * @since 2.0
107          */
108 //      public static final int AccDeprecated = IConstants.AccDeprecated;
109         
110         /**
111          * Not instantiable.
112          */
113         private Flags() {
114         }
115         /**
116          * Returns whether the given integer includes the <code>abstract</code> modifier.
117          *
118          * @param flags the flags
119          * @return <code>true</code> if the <code>abstract</code> modifier is included
120          */
121 //      public static boolean isAbstract(int flags) {
122 //              return (flags & AccAbstract) != 0;
123 //      }
124         /**
125          * Returns whether the given integer includes the indication that the 
126          * element is deprecated (<code>@deprecated</code> tag in Javadoc comment).
127          *
128          * @param flags the flags
129          * @return <code>true</code> if the element is marked as deprecated
130          */
131 //      public static boolean isDeprecated(int flags) {
132 //              return (flags & AccDeprecated) != 0;
133 //      }
134         /**
135          * Returns whether the given integer includes the <code>final</code> modifier.
136          *
137          * @param flags the flags
138          * @return <code>true</code> if the <code>final</code> modifier is included
139          */
140         public static boolean isFinal(int flags) {
141                 return (flags & AccFinal) != 0;
142         }
143         /**
144          * Returns whether the given integer includes the <code>interface</code> modifier.
145          *
146          * @param flags the flags
147          * @return <code>true</code> if the <code>interface</code> modifier is included
148          * @since 2.0
149          */
150 //      public static boolean isInterface(int flags) {
151 //              return (flags & AccInterface) != 0;
152 //      }
153         /**
154          * Returns whether the given integer includes the <code>native</code> modifier.
155          *
156          * @param flags the flags
157          * @return <code>true</code> if the <code>native</code> modifier is included
158          */
159 //      public static boolean isNative(int flags) {
160 //              return (flags & AccNative) != 0;
161 //      }
162         /**
163          * Returns whether the given integer includes the <code>private</code> modifier.
164          *
165          * @param flags the flags
166          * @return <code>true</code> if the <code>private</code> modifier is included
167          */
168         public static boolean isPrivate(int flags) {
169                 return (flags & AccPrivate) != 0;
170         }
171         /**
172          * Returns whether the given integer includes the <code>protected</code> modifier.
173          *
174          * @param flags the flags
175          * @return <code>true</code> if the <code>protected</code> modifier is included
176          */
177         public static boolean isProtected(int flags) {
178                 return (flags & AccProtected) != 0;
179         }
180         /**
181          * Returns whether the given integer includes the <code>public</code> modifier.
182          *
183          * @param flags the flags
184          * @return <code>true</code> if the <code>public</code> modifier is included
185          */
186         public static boolean isPublic(int flags) {
187                 return (flags & AccPublic) != 0;
188         }
189         /**
190          * Returns whether the given integer includes the <code>static</code> modifier.
191          *
192          * @param flags the flags
193          * @return <code>true</code> if the <code>static</code> modifier is included
194          */
195         public static boolean isStatic(int flags) {
196                 return (flags & AccStatic) != 0;
197         }
198         /**
199          * Returns whether the given integer includes the <code>strictfp</code> modifier.
200          *
201          * @param flags the flags
202          * @return <code>true</code> if the <code>strictfp</code> modifier is included
203          */
204 //      public static boolean isStrictfp(int flags) {
205 //              return (flags & AccStrictfp) != 0;
206 //      }
207         /**
208          * Returns whether the given integer includes the <code>synchronized</code> modifier.
209          *
210          * @param flags the flags
211          * @return <code>true</code> if the <code>synchronized</code> modifier is included
212          */
213 //      public static boolean isSynchronized(int flags) {
214 //              return (flags & AccSynchronized) != 0;
215 //      }
216         /**
217          * Returns whether the given integer includes the indication that the 
218          * element is synthetic.
219          *
220          * @param flags the flags
221          * @return <code>true</code> if the element is marked synthetic
222          */
223 //      public static boolean isSynthetic(int flags) {
224 //              return (flags & AccSynthetic) != 0;
225 //      }
226         /**
227          * Returns whether the given integer includes the <code>transient</code> modifier.
228          *
229          * @param flags the flags
230          * @return <code>true</code> if the <code>transient</code> modifier is included
231          */
232 //      public static boolean isTransient(int flags) {
233 //              return (flags & AccTransient) != 0;
234 //      }
235         /**
236          * Returns whether the given integer includes the <code>volatile</code> modifier.
237          *
238          * @param flags the flags
239          * @return <code>true</code> if the <code>volatile</code> modifier is included
240          */
241 //      public static boolean isVolatile(int flags) {
242 //              return (flags & AccVolatile) != 0;
243 //      }
244         /**
245          * Returns a standard string describing the given modifier flags.
246          * Only modifier flags are included in the output; the deprecated and
247          * synthetic flags are ignored if set.
248          * <p>
249          * The flags are output in the following order:
250          * <pre>
251          *   <code>public</code> <code>protected</code> <code>private</code> 
252          *   <code>static</code> 
253          *   <code>abstract</code> <code>final</code> <code>native</code> <code>synchronized</code> <code>transient</code> <code>volatile</code> <code>strictfp</code>
254          * </pre>
255          * This is a compromise between the orders specified in sections 8.1.1,
256          * 8.3.1, 8.4.3, 8.8.3, 9.1.1, and 9.3 of <em>The Java Language 
257          * Specification, Second Edition</em> (JLS2).
258          * </p> 
259          * <p>
260          * Examples results:
261          * <pre>
262          *        <code>"public static final"</code>
263          *        <code>"private native"</code>
264          * </pre>
265          * </p>
266          *
267          * @param flags the flags
268          * @return the standard string representation of the given flags
269          */
270         public static String toString(int flags) {
271                 StringBuffer sb = new StringBuffer();
272
273                 if (isPublic(flags))
274                         sb.append("public "); //$NON-NLS-1$
275                 if (isProtected(flags))
276                         sb.append("protected "); //$NON-NLS-1$
277                 if (isPrivate(flags))
278                         sb.append("private "); //$NON-NLS-1$
279                 if (isStatic(flags))
280                         sb.append("static "); //$NON-NLS-1$
281 //              if (isAbstract(flags))
282 //                      sb.append("abstract "); //$NON-NLS-1$
283                 if (isFinal(flags))
284                         sb.append("final "); //$NON-NLS-1$
285 //              if (isNative(flags))
286 //                      sb.append("native "); //$NON-NLS-1$
287 //              if (isSynchronized(flags))
288 //                      sb.append("synchronized "); //$NON-NLS-1$
289 //              if (isTransient(flags))
290 //                      sb.append("transient "); //$NON-NLS-1$
291 //              if (isVolatile(flags))
292 //                      sb.append("volatile "); //$NON-NLS-1$
293 //              if (isStrictfp(flags))
294 //                      sb.append("strictfp "); //$NON-NLS-1$
295
296                 int len = sb.length();
297                 if (len == 0)
298                         return ""; //$NON-NLS-1$
299                 sb.setLength(len - 1);
300                 return sb.toString();
301         }
302 }