1 package serp.bytecode;
2
3
4
5
6
7
8 public abstract class Annotated extends Attributes {
9
10
11
12
13
14
15
16
17
18 public Annotations getDeclaredAnnotations(boolean add) {
19 Annotations ann = (Annotations) getAttribute
20 (Constants.ATTR_ANNOTATIONS);
21 if (!add || ann != null)
22 return ann;
23 ensureBytecodeVersion();
24 return (Annotations) addAttribute(Constants.ATTR_ANNOTATIONS);
25 }
26
27
28
29
30
31
32
33 public boolean removeDeclaredAnnotations() {
34 return removeAttribute(Constants.ATTR_ANNOTATIONS);
35 }
36
37
38
39
40
41
42
43
44
45
46 public Annotations getDeclaredRuntimeAnnotations(boolean add) {
47 Annotations ann = (Annotations) getAttribute
48 (Constants.ATTR_RUNTIME_ANNOTATIONS);
49 if (!add || ann != null)
50 return ann;
51 ensureBytecodeVersion();
52 return (Annotations) addAttribute(Constants.ATTR_RUNTIME_ANNOTATIONS);
53 }
54
55
56
57
58
59
60
61 public boolean removeDeclaredRuntimeAnnotations() {
62 return removeAttribute(Constants.ATTR_RUNTIME_ANNOTATIONS);
63 }
64
65
66
67
68 private void ensureBytecodeVersion() {
69 BCClass bc = getBCClass();
70 if (bc.getMajorVersion() < Constants.MAJOR_VERSION_JAVA5) {
71 bc.setMajorVersion(Constants.MAJOR_VERSION_JAVA5);
72 bc.setMinorVersion(Constants.MINOR_VERSION_JAVA5);
73 }
74 }
75
76
77
78
79 abstract BCClass getBCClass();
80 }