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 {
35 * Public access flag. See The Java Virtual Machine Specification for more details.
38 public static final int AccPublic = IConstants.AccPublic;
40 * Private access flag. See The Java Virtual Machine Specification for more details.
43 public static final int AccPrivate = IConstants.AccPrivate;
45 * Protected access flag. See The Java Virtual Machine Specification for more details.
48 public static final int AccProtected = IConstants.AccProtected;
50 * Static access flag. See The Java Virtual Machine Specification for more details.
53 public static final int AccStatic = IConstants.AccStatic;
55 * Final access flag. See The Java Virtual Machine Specification for more details.
58 public static final int AccFinal = IConstants.AccFinal;
60 * Synchronized access flag. See The Java Virtual Machine Specification for more details.
63 // public static final int AccSynchronized = IConstants.AccSynchronized;
65 * Volatile property flag. See The Java Virtual Machine Specification for more details.
68 // public static final int AccVolatile = IConstants.AccVolatile;
70 * Transient property flag. See The Java Virtual Machine Specification for more details.
73 // public static final int AccTransient = IConstants.AccTransient;
75 * Native property flag. See The Java Virtual Machine Specification for more details.
78 // public static final int AccNative = IConstants.AccNative;
80 * Interface property flag. See The Java Virtual Machine Specification for more details.
83 // public static final int AccInterface = IConstants.AccInterface;
85 * Abstract property flag. See The Java Virtual Machine Specification for more details.
88 // public static final int AccAbstract = IConstants.AccAbstract;
90 * Strictfp property flag. See The Java Virtual Machine Specification for more details.
93 // public static final int AccStrictfp = IConstants.AccStrictfp;
95 * Super property flag. See The Java Virtual Machine Specification for more details.
98 public static final int AccSuper = IConstants.AccSuper;
100 * Synthetic property flag. See The Java Virtual Machine Specification for more details.
103 // public static final int AccSynthetic = IConstants.AccSynthetic;
105 * Deprecated property flag. See The Java Virtual Machine Specification for more details.
108 // public static final int AccDeprecated = IConstants.AccDeprecated;
116 * Returns whether the given integer includes the <code>abstract</code> modifier.
118 * @param flags the flags
119 * @return <code>true</code> if the <code>abstract</code> modifier is included
121 // public static boolean isAbstract(int flags) {
122 // return (flags & AccAbstract) != 0;
125 * Returns whether the given integer includes the indication that the
126 * element is deprecated (<code>@deprecated</code> tag in Javadoc comment).
128 * @param flags the flags
129 * @return <code>true</code> if the element is marked as deprecated
131 // public static boolean isDeprecated(int flags) {
132 // return (flags & AccDeprecated) != 0;
135 * Returns whether the given integer includes the <code>final</code> modifier.
137 * @param flags the flags
138 * @return <code>true</code> if the <code>final</code> modifier is included
140 public static boolean isFinal(int flags) {
141 return (flags & AccFinal) != 0;
144 * Returns whether the given integer includes the <code>interface</code> modifier.
146 * @param flags the flags
147 * @return <code>true</code> if the <code>interface</code> modifier is included
150 // public static boolean isInterface(int flags) {
151 // return (flags & AccInterface) != 0;
154 * Returns whether the given integer includes the <code>native</code> modifier.
156 * @param flags the flags
157 * @return <code>true</code> if the <code>native</code> modifier is included
159 // public static boolean isNative(int flags) {
160 // return (flags & AccNative) != 0;
163 * Returns whether the given integer includes the <code>private</code> modifier.
165 * @param flags the flags
166 * @return <code>true</code> if the <code>private</code> modifier is included
168 public static boolean isPrivate(int flags) {
169 return (flags & AccPrivate) != 0;
172 * Returns whether the given integer includes the <code>protected</code> modifier.
174 * @param flags the flags
175 * @return <code>true</code> if the <code>protected</code> modifier is included
177 public static boolean isProtected(int flags) {
178 return (flags & AccProtected) != 0;
181 * Returns whether the given integer includes the <code>public</code> modifier.
183 * @param flags the flags
184 * @return <code>true</code> if the <code>public</code> modifier is included
186 public static boolean isPublic(int flags) {
187 return (flags & AccPublic) != 0;
190 * Returns whether the given integer includes the <code>static</code> modifier.
192 * @param flags the flags
193 * @return <code>true</code> if the <code>static</code> modifier is included
195 public static boolean isStatic(int flags) {
196 return (flags & AccStatic) != 0;
199 * Returns whether the given integer includes the <code>strictfp</code> modifier.
201 * @param flags the flags
202 * @return <code>true</code> if the <code>strictfp</code> modifier is included
204 // public static boolean isStrictfp(int flags) {
205 // return (flags & AccStrictfp) != 0;
208 * Returns whether the given integer includes the <code>synchronized</code> modifier.
210 * @param flags the flags
211 * @return <code>true</code> if the <code>synchronized</code> modifier is included
213 // public static boolean isSynchronized(int flags) {
214 // return (flags & AccSynchronized) != 0;
217 * Returns whether the given integer includes the indication that the
218 * element is synthetic.
220 * @param flags the flags
221 * @return <code>true</code> if the element is marked synthetic
223 // public static boolean isSynthetic(int flags) {
224 // return (flags & AccSynthetic) != 0;
227 * Returns whether the given integer includes the <code>transient</code> modifier.
229 * @param flags the flags
230 * @return <code>true</code> if the <code>transient</code> modifier is included
232 // public static boolean isTransient(int flags) {
233 // return (flags & AccTransient) != 0;
236 * Returns whether the given integer includes the <code>volatile</code> modifier.
238 * @param flags the flags
239 * @return <code>true</code> if the <code>volatile</code> modifier is included
241 // public static boolean isVolatile(int flags) {
242 // return (flags & AccVolatile) != 0;
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.
249 * The flags are output in the following order:
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>
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).
262 * <code>"public static final"</code>
263 * <code>"private native"</code>
267 * @param flags the flags
268 * @return the standard string representation of the given flags
270 public static String toString(int flags) {
271 StringBuffer sb = new StringBuffer();
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$
280 sb.append("static "); //$NON-NLS-1$
281 // if (isAbstract(flags))
282 // sb.append("abstract "); //$NON-NLS-1$
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$
296 int len = sb.length();
298 return ""; //$NON-NLS-1$
299 sb.setLength(len - 1);
300 return sb.toString();