alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 * Access.java
 *
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
 * Microsystems, Inc. All Rights Reserved.
 *
 * Contributor(s): Thomas Ball
 *
 * Version: $Revision: 1.2 $
 */

package org.netbeans.modules.classfile;

/**
 * A utility class defining access flags and access utility methods.
 * Access flags are as defined by the Java Virtual Machine Specification
 * Second Edition, tables 4.1, 4.4, 4.5 and 4.7.
 *
 * @author Thomas Ball
 */
public class Access {

    /** Declared public, may be accessed from outside its package. */
    public static final int PUBLIC       = 0x0001;

    /** Declared private, usable only within the defining class. */
    public static final int PRIVATE      = 0x0002;

    /** Declared protected, may be accessed within subclasses. */
    public static final int PROTECTED    = 0x0004;

    /** Declared static. */
    public static final int STATIC       = 0x0008;

    /**
     * Declared final.  For classes this means no subclassing allowed.
     * For fields it means no further assignment allowed after initialization.
     * For methods it means that the method cannot be overridden.
     */
    public static final int FINAL        = 0x0010;

    /** Declared synchronized; invocation is wrapped in a monitor lock. */
    public static final int SYNCHRONIZED = 0x0020;

    /**
     * Treat superclass methods specially when invoked by the
     * invokespecial instruction.  This access only applies to
     * classes, and shares the same value as SYNCHRONIZED.
     */
    public static final int SUPER        = 0x0020;

    /** Declared volatile; cannot be cached. */
    public static final int VOLATILE     = 0x0040;

    /** A bridge method, generated by the compiler. */
    public static final int BRIDGE       = 0x0040;

    /** 
     * Declared transient; not written or read by a persistent object 
     * manager 
     */
    public static final int TRANSIENT    = 0x0080;

    /** Declared with a variable number of arguments. */
    public static final int VARARGS      = 0x0080;

    /** Declared native; implemented in a language other than Java. */
    public static final int NATIVE       = 0x0100;

    /** Is an interface, not a class. */
    public static final int INTERFACE    = 0x0200;

    /** Declared abstract; must not be instantiated. */
    public static final int ABSTRACT     = 0x0400;

    /** Declared strictfp; floating point mode is FP-strict. */
    public static final int STRICT       = 0x0800;

    /** Declared synthetic, not present in the source file. */
    public static final int SYNTHETIC    = 0x1000;

    /** Declared as an annotation type. */
    public static final int ANNOTATION   = 0x2000;

    /** 
     * For classes, declared as an enum type.  For fields, declared as
     * an element of an enum.
     */
    public static final int ENUM         = 0x4000;

    /**
     * Return a text representation for a given set of access flags.  
     * Here are some examples:
     * 
*
"public static final",
*
"package private", or
*
"protected transient".
*
* Note: only access flags that map to Java modifier keywords are returned. * @param access the mask of flags denoting access permission. * @return a text representation of the access flags. */ public static String toString(int access) { StringBuffer sb = new StringBuffer(); if ((access & PUBLIC) == PUBLIC) sb.append("public "); //NOI18N if ((access & PRIVATE) == PRIVATE) sb.append("private "); //NOI18N if ((access & PROTECTED) == PROTECTED) sb.append("protected "); //NOI18N if ((access & (PUBLIC | PRIVATE | PROTECTED)) == 0) sb.append("package private "); //NOI18N if ((access & STATIC) == STATIC) sb.append("static "); //NOI18N if ((access & FINAL) == FINAL) sb.append("final "); //NOI18N if ((access & SYNCHRONIZED) == SYNCHRONIZED) sb.append("synchronized "); //NOI18N if ((access & VOLATILE) == VOLATILE) sb.append("volatile "); //NOI18N if ((access & TRANSIENT) == TRANSIENT) sb.append("transient "); //NOI18N if ((access & NATIVE) == NATIVE) sb.append("native "); //NOI18N if ((access & ABSTRACT) == ABSTRACT) sb.append("abstract "); //NOI18N if ((access & STRICT) == STRICT) sb.append("strict "); //NOI18N // trim trailing space return sb.substring(0, sb.length()-1); } public static boolean isStatic(int access) { return ((access & STATIC) == STATIC); } public static final boolean isPublic(int access) { return ((access & PUBLIC) == PUBLIC); } public static final boolean isProtected(int access) { return ((access & PROTECTED) == PROTECTED); } public static final boolean isPackagePrivate(int access) { return ((access & (PUBLIC | PRIVATE | PROTECTED)) == 0); } public static final boolean isPrivate(int access) { return ((access & PRIVATE) == PRIVATE); } private Access() { // don't allow instantiation } }
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.