1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.bcel.generic;
18
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.List;
22
23 import org.apache.bcel.Const;
24 import org.apache.bcel.classfile.AccessFlags;
25 import org.apache.bcel.classfile.Attribute;
26
27
28
29
30 public abstract class FieldGenOrMethodGen extends AccessFlags implements NamedAndTyped, Cloneable {
31
32
33
34
35 @Deprecated
36 protected String name;
37
38
39
40
41 @Deprecated
42 protected Type type;
43
44
45
46
47 @Deprecated
48 protected ConstantPoolGen cp;
49
50 private final List<Attribute> attributeList = new ArrayList<>();
51
52
53 private final List<AnnotationEntryGen> annotationList = new ArrayList<>();
54
55 protected FieldGenOrMethodGen() {
56 }
57
58
59
60
61 protected FieldGenOrMethodGen(final int accessFlags) {
62 super(accessFlags);
63 }
64
65 protected void addAll(final Attribute[] attrs) {
66 Collections.addAll(attributeList, attrs);
67 }
68
69
70
71
72 public void addAnnotationEntry(final AnnotationEntryGen ag) {
73 annotationList.add(ag);
74 }
75
76
77
78
79
80
81
82 public void addAttribute(final Attribute a) {
83 attributeList.add(a);
84 }
85
86 @Override
87 public Object clone() {
88 try {
89 return super.clone();
90 } catch (final CloneNotSupportedException e) {
91 throw new UnsupportedOperationException("Clone Not Supported", e);
92 }
93 }
94
95 public AnnotationEntryGen[] getAnnotationEntries() {
96 return annotationList.toArray(AnnotationEntryGen.EMPTY_ARRAY);
97 }
98
99
100
101
102 public Attribute[] getAttributes() {
103 return attributeList.toArray(Attribute.EMPTY_ARRAY);
104 }
105
106 public ConstantPoolGen getConstantPool() {
107 return cp;
108 }
109
110
111
112
113 @Override
114 public String getName() {
115 return name;
116 }
117
118
119
120
121 public abstract String getSignature();
122
123 @Override
124 public Type getType() {
125 return type;
126 }
127
128
129
130
131 public void removeAnnotationEntries() {
132 annotationList.clear();
133 }
134
135
136
137
138 public void removeAnnotationEntry(final AnnotationEntryGen ag) {
139 annotationList.remove(ag);
140 }
141
142
143
144
145 public void removeAttribute(final Attribute a) {
146 attributeList.remove(a);
147 }
148
149
150
151
152 public void removeAttributes() {
153 attributeList.clear();
154 }
155
156 public void setConstantPool(final ConstantPoolGen cp) {
157 this.cp = cp;
158 }
159
160 @Override
161 public void setName(final String name) {
162 this.name = name;
163 }
164
165 @Override
166 public void setType(final Type type) {
167 if (type.getType() == Const.T_ADDRESS) {
168 throw new IllegalArgumentException("Type can not be " + type);
169 }
170 this.type = type;
171 }
172 }