1 23 24 25 package com.sun.jdo.api.persistence.enhancer.classfile; 26 27 import java.io.*; 28 29 33 34 public class AnnotatedMethodAttribute extends ClassAttribute { 35 36 37 public final static String expectedAttrName = "filter.annotatedMethod"; 39 40 public final static short expectedAttrVersion = 1; 41 42 43 public final static short generatedFlag = 0x1; 44 45 46 public final static short annotatedFlag = 0x2; 47 48 public final static short modifiedFlag = 0x4; 50 51 52 private short attrVersion; 53 54 55 private short annotationFlags; 56 57 60 private InsnTarget annotationRanges[]; 61 62 63 64 public short getVersion() { 65 return attrVersion; 66 } 67 68 public void setVersion(short version) { 69 attrVersion = version; 70 } 71 72 public short getFlags() { 73 return annotationFlags; 74 } 75 76 public void setFlags(short flags) { 77 annotationFlags = flags; 78 } 79 80 public InsnTarget[] getAnnotationRanges() { 81 return annotationRanges; 82 } 83 84 public void setAnnotationRanges(InsnTarget[] ranges) { 85 annotationRanges = ranges; 86 } 87 88 91 public AnnotatedMethodAttribute( 92 ConstUtf8 nameAttr, short version, short annFlags, 93 InsnTarget[] annRanges) { 94 super(nameAttr); 95 attrVersion = version; 96 annotationFlags = annFlags; 97 annotationRanges = annRanges; 98 } 99 100 101 102 static AnnotatedMethodAttribute read( 103 ConstUtf8 attrName, DataInputStream data, CodeEnv env) 104 throws IOException { 105 short version = data.readShort(); 106 short annFlags = data.readShort(); 107 108 short nRanges = data.readShort(); 109 110 InsnTarget ranges[] = new InsnTarget[nRanges*2]; 111 for (int i=0; i<nRanges; i++) { 112 ranges[i*2] = env.getTarget(data.readShort()); 113 ranges[i*2+1] = env.getTarget(data.readShort()); 114 } 115 return new AnnotatedMethodAttribute(attrName, version, annFlags, ranges); 116 } 117 118 void write(DataOutputStream out) throws IOException { 119 out.writeShort(attrName().getIndex()); 120 if (annotationRanges == null) 121 out.writeShort(2); 122 else 123 out.writeShort(4 + 2 * annotationRanges.length); 124 out.writeShort(attrVersion); 125 out.writeShort(annotationFlags); 126 if (annotationRanges == null) 127 out.writeShort(0); 128 else { 129 out.writeShort(annotationRanges.length / 2); 130 for (int i=0; i<annotationRanges.length; i++) 131 out.writeShort(annotationRanges[i].offset()); 132 } 133 } 134 135 void print(PrintStream out, int indent) { 136 ClassPrint.spaces(out, indent); 137 out.println("version: " + attrVersion); out.println(" flags: " + annotationFlags); if (annotationRanges != null) { 140 out.println("Annotations: "); for (int i=0; i<annotationRanges.length/2; i++) { 142 ClassPrint.spaces(out, indent+2); 143 out.println(annotationRanges[i*2] + " to " + annotationRanges[i*2+1]); 145 } 146 } 147 } 148 } 149 | Popular Tags |