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