001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package components;
028:
029: import jcc.Util;
030: import jcc.Str2ID;
031: import jcc.Const;
032:
033: public abstract class ClassMemberInfo extends ClassComponent {
034: public int access;
035: public int nameIndex;
036: public int typeIndex;
037: public UnicodeConstant name;
038: public UnicodeConstant type;
039: public ClassInfo parent;
040: private int ID;
041: private boolean computedID = false;
042:
043: public int index; // used by in-core output writers
044:
045: public int flags; // used by member loader
046: public final static int INCLUDE = 1; // a flag value.
047:
048: public ClassMemberInfo(int n, int t, int a, ClassInfo p) {
049: nameIndex = n;
050: typeIndex = t;
051: access = a;
052: parent = p;
053: flags = INCLUDE; // by default, we want everything.
054: }
055:
056: public boolean isStaticMember() {
057: return ((access & Const.ACC_STATIC) != 0);
058: }
059:
060: public boolean isPrivateMember() {
061: return ((access & Const.ACC_PRIVATE) != 0);
062: }
063:
064: public void resolve(ConstantObject table[]) {
065: if (resolved)
066: return;
067: name = (UnicodeConstant) table[nameIndex];
068: type = (UnicodeConstant) table[typeIndex];
069: resolved = true;
070: }
071:
072: public int getID() {
073: if (!computedID) {
074: ID = Str2ID.sigHash.getID(name, type);
075: computedID = true;
076: }
077: return ID;
078: }
079:
080: public void countConstantReferences() {
081: if (name != null)
082: name.incReference();
083: if (type != null)
084: type.incReference();
085: }
086:
087: public void externalize(ConstantPool p) {
088: name = (UnicodeConstant) p.add(name);
089: type = (UnicodeConstant) p.add(type);
090: }
091:
092: public String toString() {
093: if (resolved) {
094: return Util.accessToString(access) + " " + name.string
095: + " : " + type.string;
096: } else {
097: return Util.accessToString(access) + " [ " + nameIndex
098: + " : " + typeIndex + " ]";
099: }
100: }
101:
102: public String qualifiedName() {
103: if (resolved) {
104: return name.string + ":" + type.string;
105: } else {
106: return Util.accessToString(access) + " " + parent.className
107: + " [ " + nameIndex + " : " + typeIndex + " ]";
108: }
109: }
110:
111: /**
112: * Returns true if this is a member that can be safely renamed:
113: * e.g., it's a private or package protected method, and
114: * it's not native.
115: */
116: public boolean mayBeRenamed() {
117: if ((access & (Const.ACC_PUBLIC | Const.ACC_PROTECTED)) == 0) {
118: /* it's a private or package protected method */
119: if ((access & Const.ACC_NATIVE) == 0) {
120: return true;
121: }
122: }
123: return false;
124: }
125: }
|