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[] attributes) {
66 if (attributes != null) {
67 Collections.addAll(attributeList, attributes);
68 }
69 }
70
71
72
73
74 public void addAnnotationEntry(final AnnotationEntryGen ag) {
75 annotationList.add(ag);
76 }
77
78
79
80
81
82
83
84 public void addAttribute(final Attribute a) {
85 attributeList.add(a);
86 }
87
88 @Override
89 public Object clone() {
90 try {
91 return super.clone();
92 } catch (final CloneNotSupportedException e) {
93 throw new UnsupportedOperationException("Clone Not Supported", e);
94 }
95 }
96
97 public AnnotationEntryGen[] getAnnotationEntries() {
98 return annotationList.toArray(AnnotationEntryGen.EMPTY_ARRAY);
99 }
100
101
102
103
104 public Attribute[] getAttributes() {
105 return attributeList.toArray(Attribute.EMPTY_ARRAY);
106 }
107
108 public ConstantPoolGen getConstantPool() {
109 return cp;
110 }
111
112
113
114
115 @Override
116 public String getName() {
117 return name;
118 }
119
120
121
122
123 public abstract String getSignature();
124
125 @Override
126 public Type getType() {
127 return type;
128 }
129
130
131
132
133 public void removeAnnotationEntries() {
134 annotationList.clear();
135 }
136
137
138
139
140 public void removeAnnotationEntry(final AnnotationEntryGen ag) {
141 annotationList.remove(ag);
142 }
143
144
145
146
147 public void removeAttribute(final Attribute a) {
148 attributeList.remove(a);
149 }
150
151
152
153
154 public void removeAttributes() {
155 attributeList.clear();
156 }
157
158 public void setConstantPool(final ConstantPoolGen cp) {
159 this.cp = cp;
160 }
161
162 @Override
163 public void setName(final String name) {
164 this.name = name;
165 }
166
167 @Override
168 public void setType(final Type type) {
169 if (type.getType() == Const.T_ADDRESS) {
170 throw new IllegalArgumentException("Type can not be " + type);
171 }
172 this.type = type;
173 }
174 }