001    package edu.rice.cs.cunit.classFile.constantPool;
002    
003    import edu.rice.cs.cunit.classFile.constantPool.visitors.IPoolInfoVisitor;
004    
005    import java.io.DataInputStream;
006    import java.io.IOException;
007    
008    /**
009     * Represents a field in the constant pool.
010     *
011     * @author Mathias Ricken
012     */
013    public class FieldPoolInfo extends AClassNameTypePoolInfo {
014        /**
015         * Constructor
016         *
017         * @param clas        class information
018         * @param nameAndType NameAndType information
019         */
020        public FieldPoolInfo(ClassPoolInfo clas, NameAndTypePoolInfo nameAndType, ConstantPool cp) {
021            super(CONSTANT_Fieldref, 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 java.io.IOException
031         */
032        public FieldPoolInfo(DataInputStream dis, ConstantPool cp) throws IOException {
033            super(CONSTANT_Fieldref, dis, cp);
034        }
035    
036        /**
037         * Return a human-readable version of this constant pool object.
038         *
039         * @return string
040         */
041        public String toStringVerbose() {
042            StringBuilder s = new StringBuilder();
043            s.append("FIELD: Class = #");
044            s.append(_classInfoIndex);
045            s.append(", Name and type = #");
046            s.append(_nameAndTypeIndex);
047            s.append(' ');
048            s.append(toString());
049            return s.toString();
050        }
051    
052        /**
053         * Compare this object and another one.
054         *
055         * @param obj other object
056         *
057         * @return true if the same
058         */
059        public boolean equals(Object obj) {
060            return (obj instanceof FieldPoolInfo) && (
061                (((FieldPoolInfo)obj)._classInfoIndex == _classInfoIndex) ||
062                (((FieldPoolInfo)obj)._classInfo == _classInfo)
063                ) && (
064                (((FieldPoolInfo)obj)._nameAndTypeIndex == _nameAndTypeIndex) ||
065                (((FieldPoolInfo)obj)._nameAndType == _nameAndType)
066                );
067        }
068    
069        /**
070         * Execute a visitor.
071         *
072         * @param visitor visitor
073         * @param data    visitor-specific parameter
074         *
075         * @return visitor-specific return value
076         */
077        public <R, D> R execute(IPoolInfoVisitor<R, D> visitor, D data) {
078            return visitor.fieldCase(this, data);
079        }
080    }