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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.core;
13 import net.sourceforge.phpdt.internal.compiler.env.IConstants;
18 * Utility class for decoding modifier flags in Java elements.
20 * This class provides static methods only; it is not intended to be
21 * instantiated or subclassed by clients.
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.
30 * @see IMember#getFlags
32 public final class Flags {
34 * Constant representing the absence of any flag
37 public static final int AccDefault = 0;
39 * Public access flag. See The Java Virtual Machine Specification for more details.
42 public static final int AccPublic = IConstants.AccPublic;
44 * Private access flag. See The Java Virtual Machine Specification for more details.
47 public static final int AccPrivate = IConstants.AccPrivate;
49 * Protected access flag. See The Java Virtual Machine Specification for more details.
52 public static final int AccProtected = IConstants.AccProtected;
54 * Static access flag. See The Java Virtual Machine Specification for more details.
57 public static final int AccStatic = IConstants.AccStatic;
59 * Final access flag. See The Java Virtual Machine Specification for more details.
62 public static final int AccFinal = IConstants.AccFinal;
64 * Synchronized access flag. See The Java Virtual Machine Specification for more details.
67 // public static final int AccSynchronized = IConstants.AccSynchronized;
69 * Volatile property flag. See The Java Virtual Machine Specification for more details.
72 // public static final int AccVolatile = IConstants.AccVolatile;
74 * Transient property flag. See The Java Virtual Machine Specification for more details.
77 // public static final int AccTransient = IConstants.AccTransient;
79 * Native property flag. See The Java Virtual Machine Specification for more details.
82 // public static final int AccNative = IConstants.AccNative;
84 * Interface property flag. See The Java Virtual Machine Specification for more details.
87 public static final int AccInterface = IConstants.AccInterface;
89 * Abstract property flag. See The Java Virtual Machine Specification for more details.
92 public static final int AccAbstract = IConstants.AccAbstract;
94 * Strictfp property flag. See The Java Virtual Machine Specification for more details.
97 // public static final int AccStrictfp = IConstants.AccStrictfp;
99 * Super property flag. See The Java Virtual Machine Specification for more details.
102 public static final int AccSuper = IConstants.AccSuper;
104 * Synthetic property flag. See The Java Virtual Machine Specification for more details.
107 // public static final int AccSynthetic = IConstants.AccSynthetic;
109 * Deprecated property flag. See The Java Virtual Machine Specification for more details.
112 public static final int AccDeprecated = IConstants.AccDeprecated;
120 * Returns whether the given integer includes the <code>abstract</code> modifier.
122 * @param flags the flags
123 * @return <code>true</code> if the <code>abstract</code> modifier is included
125 public static boolean isAbstract(int flags) {
126 return (flags & AccAbstract) != 0;
129 * Returns whether the given integer includes the indication that the
130 * element is deprecated (<code>@deprecated</code> tag in Javadoc comment).
132 * @param flags the flags
133 * @return <code>true</code> if the element is marked as deprecated
135 public static boolean isDeprecated(int flags) {
136 return (flags & AccDeprecated) != 0;
139 * Returns whether the given integer includes the <code>final</code> modifier.
141 * @param flags the flags
142 * @return <code>true</code> if the <code>final</code> modifier is included
144 public static boolean isFinal(int flags) {
145 return (flags & AccFinal) != 0;
148 * Returns whether the given integer includes the <code>interface</code> modifier.
150 * @param flags the flags
151 * @return <code>true</code> if the <code>interface</code> modifier is included
154 public static boolean isInterface(int flags) {
155 return (flags & AccInterface) != 0;
158 * Returns whether the given integer includes the <code>native</code> modifier.
160 * @param flags the flags
161 * @return <code>true</code> if the <code>native</code> modifier is included
163 // public static boolean isNative(int flags) {
164 // return (flags & AccNative) != 0;
167 * Returns whether the given integer includes the <code>private</code> modifier.
169 * @param flags the flags
170 * @return <code>true</code> if the <code>private</code> modifier is included
172 public static boolean isPrivate(int flags) {
173 return (flags & AccPrivate) != 0;
176 * Returns whether the given integer includes the <code>protected</code> modifier.
178 * @param flags the flags
179 * @return <code>true</code> if the <code>protected</code> modifier is included
181 public static boolean isProtected(int flags) {
182 return (flags & AccProtected) != 0;
185 * Returns whether the given integer includes the <code>public</code> modifier.
187 * @param flags the flags
188 * @return <code>true</code> if the <code>public</code> modifier is included
190 public static boolean isPublic(int flags) {
191 return (flags & AccPublic) != 0;
194 * Returns whether the given integer includes the <code>static</code> modifier.
196 * @param flags the flags
197 * @return <code>true</code> if the <code>static</code> modifier is included
199 public static boolean isStatic(int flags) {
200 return (flags & AccStatic) != 0;
203 * Returns whether the given integer includes the <code>strictfp</code> modifier.
205 * @param flags the flags
206 * @return <code>true</code> if the <code>strictfp</code> modifier is included
208 // public static boolean isStrictfp(int flags) {
209 // return (flags & AccStrictfp) != 0;
212 * Returns whether the given integer includes the <code>synchronized</code> modifier.
214 * @param flags the flags
215 * @return <code>true</code> if the <code>synchronized</code> modifier is included
217 // public static boolean isSynchronized(int flags) {
218 // return (flags & AccSynchronized) != 0;
221 * Returns whether the given integer includes the indication that the
222 * element is synthetic.
224 * @param flags the flags
225 * @return <code>true</code> if the element is marked synthetic
227 // public static boolean isSynthetic(int flags) {
228 // return (flags & AccSynthetic) != 0;
231 * Returns whether the given integer includes the <code>transient</code> modifier.
233 * @param flags the flags
234 * @return <code>true</code> if the <code>transient</code> modifier is included
236 // public static boolean isTransient(int flags) {
237 // return (flags & AccTransient) != 0;
240 * Returns whether the given integer includes the <code>volatile</code> modifier.
242 * @param flags the flags
243 * @return <code>true</code> if the <code>volatile</code> modifier is included
245 // public static boolean isVolatile(int flags) {
246 // return (flags & AccVolatile) != 0;
249 * Returns a standard string describing the given modifier flags.
250 * Only modifier flags are included in the output; the deprecated and
251 * synthetic flags are ignored if set.
253 * The flags are output in the following order:
255 * <code>public</code> <code>protected</code> <code>private</code>
256 * <code>static</code>
257 * <code>abstract</code> <code>final</code> <code>native</code> <code>synchronized</code> <code>transient</code> <code>volatile</code> <code>strictfp</code>
259 * This is a compromise between the orders specified in sections 8.1.1,
260 * 8.3.1, 8.4.3, 8.8.3, 9.1.1, and 9.3 of <em>The Java Language
261 * Specification, Second Edition</em> (JLS2).
266 * <code>"public static final"</code>
267 * <code>"private native"</code>
271 * @param flags the flags
272 * @return the standard string representation of the given flags
274 public static String toString(int flags) {
275 StringBuffer sb = new StringBuffer();
278 sb.append("public "); //$NON-NLS-1$
279 if (isProtected(flags))
280 sb.append("protected "); //$NON-NLS-1$
281 if (isPrivate(flags))
282 sb.append("private "); //$NON-NLS-1$
284 sb.append("static "); //$NON-NLS-1$
285 // if (isAbstract(flags))
286 // sb.append("abstract "); //$NON-NLS-1$
288 sb.append("final "); //$NON-NLS-1$
289 // if (isNative(flags))
290 // sb.append("native "); //$NON-NLS-1$
291 // if (isSynchronized(flags))
292 // sb.append("synchronized "); //$NON-NLS-1$
293 // if (isTransient(flags))
294 // sb.append("transient "); //$NON-NLS-1$
295 // if (isVolatile(flags))
296 // sb.append("volatile "); //$NON-NLS-1$
297 // if (isStrictfp(flags))
298 // sb.append("strictfp "); //$NON-NLS-1$
300 int len = sb.length();
302 return ""; //$NON-NLS-1$
303 sb.setLength(len - 1);
304 return sb.toString();