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;
16 * Utility class for decoding modifier flags in Java elements.
18 * This class provides static methods only; it is not intended to be
19 * instantiated or subclassed by clients.
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.
28 * @see IMember#getFlags
30 public final class Flags {
32 * Constant representing the absence of any flag
36 public static final int AccDefault = 0;
39 * Public access flag. See The Java Virtual Machine Specification for more
44 public static final int AccPublic = IConstants.AccPublic;
47 * Private access flag. See The Java Virtual Machine Specification for more
52 public static final int AccPrivate = IConstants.AccPrivate;
55 * Protected access flag. See The Java Virtual Machine Specification for
60 public static final int AccProtected = IConstants.AccProtected;
63 * Static access flag. See The Java Virtual Machine Specification for more
68 public static final int AccStatic = IConstants.AccStatic;
71 * Final access flag. See The Java Virtual Machine Specification for more
76 public static final int AccFinal = IConstants.AccFinal;
79 * Synchronized access flag. See The Java Virtual Machine Specification for
84 // public static final int AccSynchronized = IConstants.AccSynchronized;
86 * Volatile property flag. See The Java Virtual Machine Specification for
91 // public static final int AccVolatile = IConstants.AccVolatile;
93 * Transient property flag. See The Java Virtual Machine Specification for
98 // public static final int AccTransient = IConstants.AccTransient;
100 * Native property flag. See The Java Virtual Machine Specification for more
105 // public static final int AccNative = IConstants.AccNative;
107 * Interface property flag. See The Java Virtual Machine Specification for
112 public static final int AccInterface = IConstants.AccInterface;
115 * Abstract property flag. See The Java Virtual Machine Specification for
120 public static final int AccAbstract = IConstants.AccAbstract;
123 * Strictfp property flag. See The Java Virtual Machine Specification for
128 // public static final int AccStrictfp = IConstants.AccStrictfp;
130 * Super property flag. See The Java Virtual Machine Specification for more
135 public static final int AccSuper = IConstants.AccSuper;
138 * Synthetic property flag. See The Java Virtual Machine Specification for
143 // public static final int AccSynthetic = IConstants.AccSynthetic;
145 * Deprecated property flag. See The Java Virtual Machine Specification for
150 public static final int AccDeprecated = IConstants.AccDeprecated;
159 * Returns whether the given integer includes the <code>abstract</code>
164 * @return <code>true</code> if the <code>abstract</code> modifier is
167 public static boolean isAbstract(int flags) {
168 return (flags & AccAbstract) != 0;
172 * Returns whether the given integer includes the indication that the
173 * element is deprecated (<code>@deprecated</code> tag in Javadoc comment).
177 * @return <code>true</code> if the element is marked as deprecated
179 public static boolean isDeprecated(int flags) {
180 return (flags & AccDeprecated) != 0;
184 * Returns whether the given integer includes the <code>final</code>
189 * @return <code>true</code> if the <code>final</code> modifier is
192 public static boolean isFinal(int flags) {
193 return (flags & AccFinal) != 0;
197 * Returns whether the given integer includes the <code>interface</code>
202 * @return <code>true</code> if the <code>interface</code> modifier is
206 public static boolean isInterface(int flags) {
207 return (flags & AccInterface) != 0;
211 * Returns whether the given integer includes the <code>native</code>
216 * @return <code>true</code> if the <code>native</code> modifier is
219 // public static boolean isNative(int flags) {
220 // return (flags & AccNative) != 0;
223 * Returns whether the given integer includes the <code>private</code>
228 * @return <code>true</code> if the <code>private</code> modifier is
231 public static boolean isPrivate(int flags) {
232 return (flags & AccPrivate) != 0;
236 * Returns whether the given integer includes the <code>protected</code>
241 * @return <code>true</code> if the <code>protected</code> modifier is
244 public static boolean isProtected(int flags) {
245 return (flags & AccProtected) != 0;
249 * Returns whether the given integer includes the <code>public</code>
254 * @return <code>true</code> if the <code>public</code> modifier is
257 public static boolean isPublic(int flags) {
258 return (flags & AccPublic) != 0;
262 * Returns whether the given integer includes the <code>static</code>
267 * @return <code>true</code> if the <code>static</code> modifier is
270 public static boolean isStatic(int flags) {
271 return (flags & AccStatic) != 0;
275 * Returns whether the given integer includes the <code>strictfp</code>
280 * @return <code>true</code> if the <code>strictfp</code> modifier is
283 // public static boolean isStrictfp(int flags) {
284 // return (flags & AccStrictfp) != 0;
287 * Returns whether the given integer includes the <code>synchronized</code>
292 * @return <code>true</code> if the <code>synchronized</code> modifier
295 // public static boolean isSynchronized(int flags) {
296 // return (flags & AccSynchronized) != 0;
299 * Returns whether the given integer includes the indication that the
300 * element is synthetic.
304 * @return <code>true</code> if the element is marked synthetic
306 // public static boolean isSynthetic(int flags) {
307 // return (flags & AccSynthetic) != 0;
310 * Returns whether the given integer includes the <code>transient</code>
315 * @return <code>true</code> if the <code>transient</code> modifier is
318 // public static boolean isTransient(int flags) {
319 // return (flags & AccTransient) != 0;
322 * Returns whether the given integer includes the <code>volatile</code>
327 * @return <code>true</code> if the <code>volatile</code> modifier is
330 // public static boolean isVolatile(int flags) {
331 // return (flags & AccVolatile) != 0;
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.
338 * The flags are output in the following order:
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>
378 * "public static final"
381 * "private native"
389 * @return the standard string representation of the given flags
391 public static String toString(int flags) {
392 StringBuffer sb = new StringBuffer();
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$
401 sb.append("static "); //$NON-NLS-1$
402 // if (isAbstract(flags))
403 // sb.append("abstract "); //$NON-NLS-1$
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$
417 int len = sb.length();
419 return ""; //$NON-NLS-1$
420 sb.setLength(len - 1);
421 return sb.toString();