1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.jdo.impl.enhancer.classfile;
19
20 import java.io.*;
21
22 /***
23 * AnnotatedMethodAttribute represents a class level attribute
24 * class file which identifies the level of annotation of the class.
25 */
26 public class AnnotatedMethodAttribute extends ClassAttribute {
27
28
29 public final static String expectedAttrName = "filter.annotatedMethod";
30
31
32 public final static short expectedAttrVersion = 1;
33
34
35 public final static short generatedFlag = 0x1;
36
37
38 public final static short annotatedFlag = 0x2;
39
40 /* Bit mask indicating that the class was "repackaged" *//package-summary/html">class="comment"> Bit mask indicating that the class was "repackaged" *//package-summary.html">
41 public final static short modifiedFlag = 0x4;
42
43
44 private short attrVersion;
45
46
47 private short annotationFlags;
48
49
50
51
52 private InsnTarget annotationRanges[];
53
54
55
56 public short getVersion() {
57 return attrVersion;
58 }
59
60 public void setVersion(short version) {
61 attrVersion = version;
62 }
63
64 public short getFlags() {
65 return annotationFlags;
66 }
67
68 public void setFlags(short flags) {
69 annotationFlags = flags;
70 }
71
72 public InsnTarget[] getAnnotationRanges() {
73 return annotationRanges;
74 }
75
76 public void setAnnotationRanges(InsnTarget[] ranges) {
77 annotationRanges = ranges;
78 }
79
80 /***
81 * Constructor
82 */
83 public AnnotatedMethodAttribute(
84 ConstUtf8 nameAttr, short version, short annFlags,
85 InsnTarget[] annRanges) {
86 super(nameAttr);
87 attrVersion = version;
88 annotationFlags = annFlags;
89 annotationRanges = annRanges;
90 }
91
92 /* package local methods *//package-summary/html">class="comment"> package local methods *//package-summary.html">
93
94 static AnnotatedMethodAttribute read(
95 ConstUtf8 attrName, DataInputStream data, CodeEnv env)
96 throws IOException {
97 short version = data.readShort();
98 short annFlags = data.readShort();
99
100 short nRanges = data.readShort();
101
102 InsnTarget ranges[] = new InsnTarget[nRanges*2];
103 for (int i=0; i<nRanges; i++) {
104 ranges[i*2] = env.getTarget(data.readShort());
105 ranges[i*2+1] = env.getTarget(data.readShort());
106 }
107 return new AnnotatedMethodAttribute(attrName, version, annFlags, ranges);
108 }
109
110 void write(DataOutputStream out) throws IOException {
111 out.writeShort(attrName().getIndex());
112 if (annotationRanges == null)
113 out.writeShort(2);
114 else
115 out.writeShort(4 + 2 * annotationRanges.length);
116 out.writeShort(attrVersion);
117 out.writeShort(annotationFlags);
118 if (annotationRanges == null)
119 out.writeShort(0);
120 else {
121 out.writeShort(annotationRanges.length / 2);
122 for (int i=0; i<annotationRanges.length; i++)
123 out.writeShort(annotationRanges[i].offset());
124 }
125 }
126
127 void print(PrintStream out, int indent) {
128 ClassPrint.spaces(out, indent);
129 out.println("version: " + attrVersion);
130 out.println(" flags: " + annotationFlags);
131 if (annotationRanges != null) {
132 out.println("Annotations: ");
133 for (int i=0; i<annotationRanges.length/2; i++) {
134 ClassPrint.spaces(out, indent+2);
135 out.println(annotationRanges[i*2] + " to " +
136 annotationRanges[i*2+1]);
137 }
138 }
139 }
140 }