001    /*
002      Copyright (C) 2002-2003 Renaud Pawlak <renaud@aopsys.com>
003    
004      This program is free software; you can redistribute it and/or modify
005      it under the terms of the GNU Lesser General Public License as
006      published by the Free Software Foundation; either version 2 of the
007      License, or (at your option) any later version.
008    
009      This program is distributed in the hope that it will be useful,
010      but WITHOUT ANY WARRANTY; without even the implied warranty of
011      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012      GNU Lesser General Public License for more details.
013    
014      You should have received a copy of the GNU Lesser General Public
015      License along with this program; if not, write to the Free Software
016      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
017      USA */
018    
019    package org.objectweb.jac.ide;
020    
021    import org.objectweb.jac.util.Strings;
022    
023    
024    /**
025     * A member item of a class such as a field or a method.
026     */
027    public abstract class Member extends TypedElement implements Visibility {
028    
029        Class parent;
030       
031        /**
032         * Get the value of parent.
033         * @return value of parent.
034         */
035        public Class getParent() {
036            return parent;
037        }
038       
039        /**
040         * Set the value of parent.
041         * @param v  Value to assign to parent.
042         */
043        public void setParent(Class  v) {
044            this.parent = v;
045        }
046          
047        public abstract String getPrototype();
048    
049        /** Flag indicating if the member is static or not*/
050        boolean isStatic = false;
051        /** Returns value of isStatic field */
052        public boolean isStatic() {
053            return isStatic;
054        }
055        /** Sets value of isStatic field */
056        public void setStatic(boolean isStatic) {
057            this.isStatic = isStatic;
058        }
059    
060        /**
061         * Returns a string of all the modifiers of a member item (field or
062         * method)
063         * @return a String with the modifiers, seperated by spaces
064         * @see #isStatic()
065         * @see #getVisibility()
066         */
067        public String getModifiers() {
068            String modifiers = "";
069            switch(visibility) {
070                case PUBLIC: modifiers = "public"; break;
071                case PROTECTED: modifiers = "protected"; break;
072                case PRIVATE: modifiers = "private"; break;
073            }
074            if (isStatic) {
075                modifiers += " static";
076            }
077            return modifiers;
078        }
079    
080        public String getFullName() {
081            return parent.getFullName()+"."+getName();
082        }
083    
084        public String getGenerationName() {
085            return Strings.toUSAscii(getName());
086        }
087    
088        public String getGenerationFullName() {
089            return Strings.toUSAscii(getFullName());
090        }
091    
092        public Project getProject() {
093            if (parent!=null)
094                return parent.getProject();
095            else
096                return null;
097        }
098    
099        int visibility = PUBLIC;
100        public int getVisibility() {
101            return visibility;
102        }
103        public void setVisibility(int newVisibility) {
104            this.visibility = newVisibility;
105        }
106       
107    }