1 15 16 package javassist.bytecode; 17 18 import java.util.Map ; 19 import java.io.IOException ; 20 import java.io.DataInputStream ; 21 import java.io.ByteArrayOutputStream ; 22 23 import javassist.bytecode.AnnotationsAttribute.Copier; 24 import javassist.bytecode.AnnotationsAttribute.Parser; 25 import javassist.bytecode.annotation.*; 26 27 40 public class ParameterAnnotationsAttribute extends AttributeInfo { 41 45 public static final String visibleTag 46 = "RuntimeVisibleParameterAnnotations"; 47 48 52 public static final String invisibleTag 53 = "RuntimeInvisibleParameterAnnotations"; 54 65 public ParameterAnnotationsAttribute(ConstPool cp, String attrname, 66 byte[] info) { 67 super(cp, attrname, info); 68 } 69 70 81 public ParameterAnnotationsAttribute(ConstPool cp, String attrname) { 82 this(cp, attrname, new byte[] { 0 }); 83 } 84 85 88 ParameterAnnotationsAttribute(ConstPool cp, int n, DataInputStream in) 89 throws IOException 90 { 91 super(cp, n, in); 92 } 93 94 97 public int numParameters() { 98 return info[0] & 0xff; 99 } 100 101 104 public AttributeInfo copy(ConstPool newCp, Map classnames) { 105 Copier copier = new Copier(info, constPool, newCp, classnames); 106 try { 107 copier.parameters(); 108 return new ParameterAnnotationsAttribute(newCp, getName(), 109 copier.close()); 110 } 111 catch (Exception e) { 112 throw new RuntimeException (e.toString()); 113 } 114 } 115 116 128 public Annotation[][] getAnnotations() { 129 try { 130 return new Parser(info, constPool).parseParameters(); 131 } 132 catch (Exception e) { 133 throw new RuntimeException (e.toString()); 134 } 135 } 136 137 146 public void setAnnotations(Annotation[][] params) { 147 ByteArrayOutputStream output = new ByteArrayOutputStream (); 148 AnnotationsWriter writer = new AnnotationsWriter(output, constPool); 149 try { 150 int n = params.length; 151 writer.numParameters(n); 152 for (int i = 0; i < n; ++i) { 153 Annotation[] anno = params[i]; 154 writer.numAnnotations(anno.length); 155 for (int j = 0; j < anno.length; ++j) 156 anno[j].write(writer); 157 } 158 159 writer.close(); 160 } 161 catch (IOException e) { 162 throw new RuntimeException (e); } 164 165 set(output.toByteArray()); 166 } 167 } 168 | Popular Tags |