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

/*
 *                 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-2004 Sun
 * Microsystems, Inc. All Rights Reserved.
 */

package org.openide.src;

import java.io.*;

/** Superclass for containable Java source members
* (fields, methods and classes). Provides support
* for associating this element with a declaring class.
*
* @author Petr Hamernik, Jaroslav Tulach
*/
public abstract class MemberElement extends Element implements Cloneable {
    /** the class this element belongs to */
    private ClassElement declaringClass;

    static final long serialVersionUID =7896378970641663987L;

    /** Create a member element.
    * @param impl the pluggable implementation
    * @param declaringClass the class this element belongs to, or null if unattached
    */
    protected MemberElement(MemberElement.Impl impl, ClassElement declaringClass) {
        super(impl);
        this.declaringClass = declaringClass;
    }

    /** @return the current implementation. */
    final MemberElement.Impl getMemberImpl() {
        return (MemberElement.Impl) impl;
    }

    // [PENDING] Modifier explicitly disallows assuming its constants
    // are bitwise composable--this is technically illegal
    // (although in fact they are and this will probably never change)

    /** Get the modifier flags for this element.
    * Constrained by {@link #getModifiersMask}.
    * @return disjunction of constants from {@link Modifier}
    */
    public final int getModifiers() {
        return getMemberImpl().getModifiers();
    }

    /** Set the modifier flags for this element.
    * @param mod disjunction of constants from {@link Modifier}
    * @throws SourceException if impossible (e.g. if mod & ~ getModifiersMask() != 0)
    */
    public final void setModifiers(int mod) throws SourceException {
        getMemberImpl().setModifiers(mod);
    }

    /** Get the permitted modifiers for this type of element.
    * @return disjunction of constants from {@link Modifier}
    */
    public abstract int getModifiersMask();

    /** Test whether declaring class is interface or class.
    * @return true for interfaces otherwise false
    */
    boolean isDeclaredInInterface() {
        return (declaringClass != null) && (declaringClass.isInterface());
    }

    /** Get the name of this member.
    * @return the name
    */
    public final Identifier getName() {
        return getMemberImpl().getName();
    }

    /** Set the name of this member.
    * @param name the name
    * @throws SourceException if impossible
    */
    public void setName(Identifier name) throws SourceException {
        getMemberImpl().setName(name);
        updateConstructorsNames(name);
    }

    /** Implemented in ClassElement - update names of the constructors.
    */
    void updateConstructorsNames(Identifier name) throws SourceException {
    }

    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    // no --jglick
    /* This field is automaticly sychnronized
    * when a MemberElement is added to the class. */
    /** Get the declaring class.
    *
    * @return the class that owns this member element, or null if the element is not
    *    attached to any class
    */
    public final ClassElement getDeclaringClass () {
        return declaringClass;
    }

    /** Pluggable implementation of member elements.
    * @see MemberElement
    */
    public interface Impl extends Element.Impl {
        /** @deprecated Only public by accident. */
        /* public static final */ long serialVersionUID = 2037286733482347462L;
        /** Get the modifier flags for this element.
         * Constrained by {@link MemberElement#getModifiersMask}.
         * @return disjunction of constants from {@link Modifier}
         */
        public int getModifiers();

        /** Set the modifier flags for this element.
         * @param mod disjunction of constants from {@link Modifier}
         * @throws SourceException if impossible (e.g. if mod & ~ memberElt.getModifiersMask() != 0)
         */
        public void setModifiers(int mod) throws SourceException;

        /** Get the name of this member.
         * @return the name
         */
        public Identifier getName();

        /** Set the name of this member.
         * @param name the name
         * @throws SourceException if impossible
         */
        public void setName(Identifier name) throws SourceException;
    }

    /** Default implementation of the Impl interface.
    * It just holds the property values.
    */
    static abstract class Memory extends Element.Memory implements MemberElement.Impl {
        /** Modifiers for this element */
        private int mod;

        /** Name of this element */
        private Identifier name;

        static final long serialVersionUID =1876531129266668488L;
        /** Default */
        public Memory () {
        }

        /** Copy */
        public Memory (MemberElement el) {
            mod = el.getModifiers ();
            name = el.getName ();
        }

        /** Getter for modifiers for this element.
        * @see java.lang.reflect.Modifier
        * @return constants from java.lang.reflect.Modifier
        */
        public int getModifiers() {
            return mod;
        }

        /** Setter for modifiers for this element.
        * @see java.lang.reflect.Modifier
        * @param mod constants from java.lang.reflect.Modifier
        */
        public void setModifiers(int mod) {
            int old = this.mod;
            this.mod = mod;
            firePropertyChange (PROP_MODIFIERS, new Integer (old), new Integer (mod));
        }

        /** Getter for name of the field.
        * @return the name
        */
        public synchronized Identifier getName() {
            if (name == null) {
                // lazy initialization !?
                name = Identifier.create(""); // NOI18N
            }
            return name;
        }

        /** Setter for name of the field.
        * @param name the name of the field
        */
        public synchronized void setName(Identifier name) {
            Identifier old = this.name;
            this.name = name;
            firePropertyChange (PROP_NAME, old, name);
        }
    
        public void markCurrent(boolean after) {
            ClassElement decl = ((MemberElement)element).getDeclaringClass();
            if (decl == null) {
                throw new IllegalStateException();
            }
            ((ClassElement.Memory)decl.getCookie(ClassElement.Memory.class)).markCurrent(element, after);
        }
    }
}
... 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.