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