001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.classreader;
034:
035: import java.io.*;
036:
037: public abstract class FeatureRef_info extends ConstantPoolEntry {
038: private int classIndex;
039: private int nameAndTypeIndex;
040:
041: public FeatureRef_info(ConstantPool constantPool, DataInputStream in)
042: throws IOException {
043: super (constantPool);
044:
045: classIndex = in.readUnsignedShort();
046: nameAndTypeIndex = in.readUnsignedShort();
047: }
048:
049: public int getClassIndex() {
050: return classIndex;
051: }
052:
053: public Class_info getRawClass() {
054: return (Class_info) getConstantPool().get(getClassIndex());
055: }
056:
057: public String getClassName() {
058: return getRawClass().toString();
059: }
060:
061: public String getClassSimpleName() {
062: return getRawClass().getSimpleName();
063: }
064:
065: public int getNameAndTypeIndex() {
066: return nameAndTypeIndex;
067: }
068:
069: public NameAndType_info getRawNameAndType() {
070: return (NameAndType_info) getConstantPool().get(
071: getNameAndTypeIndex());
072: }
073:
074: public String getNameAndType() {
075: StringBuffer result = new StringBuffer();
076:
077: NameAndType_info nat = getRawNameAndType();
078:
079: result.append(nat.getName()).append(nat.getType());
080:
081: return result.toString();
082: }
083:
084: public abstract String getName();
085:
086: public String getFullName() {
087: return getClassName() + "." + getName();
088: }
089:
090: public abstract String getSignature();
091:
092: public String getFullSignature() {
093: return getClassName() + "." + getSignature();
094: }
095:
096: public String toString() {
097: StringBuffer result = new StringBuffer();
098:
099: Class_info c = getRawClass();
100: NameAndType_info nat = getRawNameAndType();
101:
102: result.append(c).append(".").append(nat.getName()).append(
103: nat.getType());
104:
105: return result.toString();
106: }
107:
108: public int hashCode() {
109: return getRawClass().hashCode()
110: ^ getRawNameAndType().hashCode();
111: }
112:
113: public boolean equals(Object object) {
114: boolean result = false;
115:
116: if (this == object) {
117: result = true;
118: } else if (object != null
119: && this .getClass().equals(object.getClass())) {
120: FeatureRef_info other = (FeatureRef_info) object;
121: result = this.getRawClass().equals(other.getRawClass())
122: && this.getRawNameAndType().equals(
123: other.getRawNameAndType());
124: }
125:
126: return result;
127: }
128: }
|