001 package edu.rice.cs.cunit.classFile.attributes;
002
003 import edu.rice.cs.cunit.classFile.attributes.visitors.IAttributeVisitor;
004 import edu.rice.cs.cunit.classFile.code.instructions.LineNumberTable;
005 import edu.rice.cs.cunit.classFile.constantPool.APoolInfo;
006 import edu.rice.cs.cunit.classFile.constantPool.AUTFPoolInfo;
007 import edu.rice.cs.cunit.classFile.constantPool.ConstantPool;
008 import edu.rice.cs.cunit.classFile.constantPool.visitors.CheckUTFVisitor;
009 import edu.rice.cs.cunit.util.Types;
010
011 import java.util.ArrayList;
012
013 /**
014 * Represents the Signature attribute in a class file.
015 *
016 * @author Mathias Ricken
017 */
018 public class SignatureAttributeInfo extends AAttributeInfo {
019 /**
020 * Constructor.
021 *
022 * @param name attribute name
023 * @param data attribute data
024 * @param cp constant pool
025 *
026 * @throws ClassFormatError
027 */
028 public SignatureAttributeInfo(AUTFPoolInfo name, byte[] data, ConstantPool cp) throws ClassFormatError {
029 super(name, data, cp);
030 }
031
032 /**
033 * Return the source file name information.
034 *
035 * @return source file name information
036 *
037 * @throws ClassFormatError
038 */
039 public AUTFPoolInfo getSignature() throws ClassFormatError {
040 return _constantPool.get(Types.ushortFromBytes(_data, 0)).execute(CheckUTFVisitor.singleton(), null);
041 }
042
043 /**
044 * Set the source file name information.
045 *
046 * @param newFileName constant pool
047 */
048 public void setSignature(AUTFPoolInfo newFileName) {
049 _data = new byte[2];
050 Types.bytesFromShort(_constantPool.indexOf(newFileName), _data, 0);
051 }
052
053 /**
054 * Execute a visitor on this attribute.
055 *
056 * @param visitor visitor
057 * @param param visitor-specific parameter
058 *
059 * @return visitor-specific return value
060 */
061 public <R, D> R execute(IAttributeVisitor<R, D> visitor, D param) {
062 return visitor.signatureCase(this, param);
063 }
064
065 /**
066 * Adjust program counter values contained in this attribute, starting at startPC, by adding deltaPC to them.
067 *
068 * @param startPC program counter to start at
069 * @param deltaPC change in program counter values
070 */
071 public void adjustPC(int startPC, int deltaPC) {
072 // nothing to do
073 }
074
075 /**
076 * Translate the program counter values contained in this attribute from an old line number table to a new one.
077 *
078 * @param index critical point (insertion or deletion point)
079 * @param deltaIndex delta value to add to all old line numbers greater than the critical point
080 * @param oldLnt old line number table
081 * @param newLnt new line number table
082 */
083 public void translatePC(int index, int deltaIndex, LineNumberTable oldLnt, LineNumberTable newLnt) {
084 // nothing to do
085 }
086
087 /**
088 * Creates and returns a copy of this object.
089 */
090 public Object clone() throws CloneNotSupportedException {
091 return super.clone();
092 }
093
094 /**
095 * Return a human-readable version of this attribute.
096 *
097 * @return string
098 */
099 public String toString() {
100 return "Signature = "+getSignature().toString();
101 }
102
103 /**
104 * Returns the name of the attribute as it appears in the class file.
105 *
106 * @return name of the attribute.
107 */
108 public static String getAttributeName() {
109 return "Signature";
110 }
111 }