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