001 package sysModel.classFile.constantPool; 002 003 import sysModel.classFile.constantPool.visitors.IPoolInfoVisitor; 004 005 import java.io.DataInputStream; 006 import java.io.IOException; 007 008 /** 009 * Represents a method in the constant pool. 010 * 011 * @author Mathias Ricken 012 */ 013 public class MethodPoolInfo extends AClassNameTypePoolInfo { 014 /** 015 * Constructor 016 * 017 * @param clas class information 018 * @param nameAndType NameAndType information 019 */ 020 public MethodPoolInfo(ClassPoolInfo clas, NameAndTypePoolInfo nameAndType, ConstantPool cp) { 021 super(CONSTANT_Methodref, clas, nameAndType, cp); 022 } 023 024 /** 025 * Constructor reading from a stream. 026 * 027 * @param dis input stream 028 * @param cp constant pool 029 * 030 * @throws IOException 031 */ 032 public MethodPoolInfo(DataInputStream dis, ConstantPool cp) throws IOException { 033 super(CONSTANT_Methodref, dis, cp); 034 } 035 036 /** 037 * Return a human-readable version of this constant pool object. 038 * 039 * @return string 040 */ 041 public String toString() { 042 StringBuffer s; 043 044 s = new StringBuffer(); 045 s.append("METHOD: Class = #"); 046 s.append(_classInfoIndex); 047 s.append(", Name and type = #"); 048 s.append(_nameAndTypeIndex); 049 050 return s.toString(); 051 } 052 053 /** 054 * Return a human-readable version of this constant pool object. 055 * 056 * @return string 057 */ 058 public String toStringVerbose() { 059 return toString(); 060 } 061 062 /** 063 * Compare this object and another one. 064 * 065 * @param obj other object 066 * 067 * @return true if the same 068 */ 069 public boolean equals(Object obj) { 070 return (obj instanceof MethodPoolInfo) && ( 071 (((MethodPoolInfo)obj)._classInfoIndex == _classInfoIndex) || 072 (((MethodPoolInfo)obj)._classInfo == _classInfo) 073 ) && ( 074 (((MethodPoolInfo)obj)._nameAndTypeIndex == _nameAndTypeIndex) || 075 (((MethodPoolInfo)obj)._nameAndType == _nameAndType) 076 ); 077 } 078 079 /** 080 * Execute a visitor. 081 * 082 * @param visitor visitor 083 * @param data visitor-specific parameter 084 * 085 * @return visitor-specific return value 086 */ 087 public <R, D> R execute(IPoolInfoVisitor<R, D> visitor, D data) { 088 return visitor.methodCase(this, data); 089 } 090 }