001    package edu.rice.cs.cunit.classFile.attributes;
002    
003    import edu.rice.cs.cunit.classFile.constantPool.AUTFPoolInfo;
004    import edu.rice.cs.cunit.classFile.constantPool.ConstantPool;
005    import edu.rice.cs.cunit.classFile.attributes.visitors.IAttributeVisitor;
006    import edu.rice.cs.cunit.classFile.code.instructions.LineNumberTable;
007    
008    import java.io.ByteArrayOutputStream;
009    import java.io.IOException;
010    
011    /**
012     * Represents the AnnotationDefault attribute in a class file.
013     *
014     * @author Mathias Ricken
015     */
016    public class AnnotationDefaultAttributeInfo extends AAttributeInfo {
017        /**
018         * Constructor.
019         *
020         * @param name attribute name
021         * @param data attribute data
022         * @param cp   constant pool
023         *
024         * @throws ClassFormatError
025         */
026        public AnnotationDefaultAttributeInfo(AUTFPoolInfo name, byte[] data, ConstantPool cp) throws ClassFormatError {
027            super(name, data, cp);
028        }
029    
030        /**
031         * Execute a visitor on this attribute.
032         *
033         * @param visitor visitor
034         * @param param   visitor-specific parameter
035         *
036         * @return visitor-specific return value
037         */
038        public <R, D> R execute(IAttributeVisitor<R, D> visitor, D param) {
039            return visitor.annotationDefaultCase(this, param);
040        }
041    
042        /**
043         * Returns the name of the attribute as it appears in the class file.
044         *
045         * @return name of the attribute.
046         */
047        public static String getAttributeName() {
048            return "AnnotationDefault";
049        }
050    
051        /**
052         * Returns the default value stored in this attribute.
053         *
054         * @return default value
055         */
056        public AAnnotationsAttributeInfo.Annotation.AMemberValue getDefaultValue() {
057            return AAnnotationsAttributeInfo.Annotation.AMemberValue.read(_constantPool, _data, 0);
058        }
059    
060        /**
061         * Set the default value stored in this attribute.
062         *
063         * @param defaultValue new default value
064         */
065        public void setDefaultValue(AAnnotationsAttributeInfo.Annotation.AMemberValue defaultValue) {
066            ByteArrayOutputStream baos = new ByteArrayOutputStream();
067            try {
068                defaultValue.writeToByteArrayOutputStream(_constantPool, baos);
069            }
070            catch(IOException ioe) {
071                throw new ClassFormatError("Error while writing out default value");
072            }
073            setData(baos.toByteArray());
074        }
075    
076        /**
077         * Return a human-readable version of this attribute.
078         *
079         * @return string
080         */
081        public String toString() {
082            StringBuilder x = new StringBuilder();
083            x.append(_name);
084            x.append(" <");
085            x.append(getDefaultValue().toString());
086            x.append(">");
087            return x.toString();
088        }
089    
090    
091        /**
092         * Adjust program counter values contained in this attribute, starting at startPC, by adding deltaPC to them.
093         *
094         * @param startPC program counter to start at
095         * @param deltaPC change in program counter values
096         */
097        public void adjustPC(int startPC, int deltaPC) {
098            // nothing to do
099        }
100    
101        /**
102         * Translate the program counter values contained in this attribute from an old line number table to a new one.
103         *
104         * @param index      critical point (insertion or deletion point)
105         * @param deltaIndex delta value to add to all old line numbers greater than the critical point
106         * @param oldLnt     old line number table
107         * @param newLnt     new line number table
108         */
109        public void translatePC(int index, int deltaIndex, LineNumberTable oldLnt, LineNumberTable newLnt) {
110            // nothing to do
111        }
112    }